我目前有 laravel illuminate 数据库和在 laravel 之外的 Eloquent 工作。
我现在也在尝试让缓存正常工作。
这就是我现在的全部。
<?php
require dirname(dirname(__DIR__)) . '/vendor/autoload.php';
require dirname(__DIR__) . '/config.php';
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Cache\CacheManager as CacheManager;
$dbc = new DB;
$dbc->addConnection(array(
'driver' => 'mysql',
'host' => DB_HOST,
'database' => DB_NAME,
'username' => DB_USER,
'password' => DB_PASSWORD,
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
));
# Set the default fetch mode for all queries
$dbc->setFetchMode(PDO::FETCH_CLASS);
# Set up the cache
$container = $dbc->getContainer();
$container['config']['cache.driver'] = 'memcached';
$container['config']['cache.memcached'] = array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 100);
$container->offsetGet('config')->offsetSet('cache.driver', 'array');
$cacheManager = new CacheManager($container);
$dbc->setCacheManager($cacheManager);
$dbc->setAsGlobal();
$dbc->bootEloquent();
global $dbc;
这对我不起作用,尽管安装了 memcached 和 php 模块 memcached 并且可以正常工作。
更新 我没有收到此配置的任何错误。我只是没有看到任何东西进入 memcached。我已经使用以下代码行进行了测试。
$dbc->table('users')->limit(10)->cacheTags(array('people', 'authors'))->remember(10)->get();
同时在盒子上观看
[root@localhost vagrant]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
stats items
END
最佳答案
好吧,我遇到了同样的问题,有一个名为:Using Laravel's Illuminate Components Independently 的 github 存储库。 完美解决了我的问题, 链接在这里: https://github.com/mattstauffer/Torch
关于php - laravel 之外的 Laravel 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29129549/