PHP 活动记录内存缓存


PHP Active Record Memcached

如何使用phpactiverecord memcached? 有人可以帮助我吗?

$database = array(
    'connection' => 'local',
    'local' => 'mysql://username:password@localhost/database?charset=utf8',
    'server' => 'mysql://username:password@localhost/database?charset=utf8',
    'memcache' => 'memcache://localhost:11211'
);
ActiveRecord'Config::initialize(function($config) use ($database) {
    $config->set_connections($database);
    $config->set_default_connection($database['connection']);
    $config->set_cache($database['memcache'], array('namespace' => 'My', 'expire' => 120));
});

默认情况下,我从这样的管理模型中获取管理员数据

use My'Admin;
use ActiveRecord'Model;
class Admin extends Model {
    static $table_name = 'web_admin';
}
print_r(Admin::all());

那么,如何将管理数据设置为memcached以及如何获取该数据?

他们的文档没有解释如何使用缓存的任何内容,但他们的 github 链接说您只需将缓存变量设置为 TRUE 即可做到这一点。所以你需要设置。

static $cache = TRUE;

在要为其缓存查询的模型中。