Laravel缓存在Laravel之外


Laravel cache outside of laravel

我目前拥有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

好吧,我遇到了同样的问题,有一个github存储库名为:独立使用Laravel的Illuminate组件。这完全解决了我的问题,以下是链接:https://github.com/mattstauffer/Torch

这可能有助于使用Laravel 5.8中的缓存外观,在我的情况下,我正在为Codeigner项目使用文件缓存。

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);