php - laravel 之外的 Laravel 缓存

标签 php laravel memcached illuminate-container

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

相关文章:

php - 从页表用户 Codeigniter 显示新页表详细信息

php - Laravel 通过另一个 URL 上传图像并将其存储在数据库中

javascript - 如何用 'v-for' 实现 'v-if' ?

用于海量数据的 Laravel 惰性集合

java - Spymemcached 的 MemcachedClient#delete 什么时候返回 false?

php - 数据表 AJAX - 传递数组

php - 在 php 中使用 isset() over @ 是否有任何必要的原因

java - memcached 自定义序列化器 jar 的正确位置

jsp - session ID 定期更改 (nginx/tomcat/mamcached/MSM)

php - 当我连接两个表时,不返回空值。返回以前的数据