我目前在laravel以外有laravel照明数据库和雄辩的工作。
我现在正试图让缓存工作。
这就是我现在所拥有的。
<?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
答案 0 :(得分:2)
嗯,我遇到了同样的问题,有一个名为的github存储库:独立使用Laravel的Illuminate组件。 这完全解决了我的问题, 链接在这里: https://github.com/mattstauffer/Torch
答案 1 :(得分:0)
这可能会对使用Laravel 5.8中的缓存外观的人有所帮助,就我而言,我正在为Codeigniter项目使用文件缓存。
use \Illuminate\Cache\CacheManager;
use \Illuminate\Filesystem\Filesystem;
$container = $capsule->getContainer();
$container['config']['cache.stores.file'] = array(
'driver' => 'file',
'path' => \APPPATH . 'cache/eloquent' // use your own cache directory
);
$container['config']['cache.default'] = 'file';
$container['files'] = new Filesystem();
$cacheManager = new CacheManager( $container );
$app->instance( 'cache', $cacheManager);