寻找具有多个后端存储适配器的 PHP 缓存库


Looking for a PHP Caching Library with multiple back-end storage adapters

我正在寻找一个具有多个后端存储适配器的 PHP 缓存库。例如,可以将缓存保存在文件或内存缓存中的东西。

以下是我找到的一些库:

  • 可扩展的 PHP 缓存库
  • 光线缓存
  • Zend_Cache
  • SabreCache

PEAR 也有两个库;缓存和Cache_Lite。不幸的是,两者都不是最新的,并且不提供memcached后端。

Zend_Cache是一个非常好的库,具有许多适配器,并且易于实现自定义适配器。Zend正在尽最大努力使其库保持最新状态。

Zend_Cache易于使用

且非常灵活 http://framework.zend.com/manual/1.12/en/zend.cache.introduction.html

例如。

$frontendOptions = array(
    'lifetime' => 7200, // cache lifetime of 2 hours
    'automatic_serialization' => true
);
$backendOptions = array(
    'cache_dir' => './tmp/' // Directory where to put the cache files
);
// getting a Zend_Cache_Core object
$cache = Zend_Cache::factory(
    'Core',
    'File',
    $frontendOptions,
    $backendOptions
);
if (($result = $cache->load('myresult')) === false) {
    // cache miss; connect to the database
    $db = Zend_Db::factory(/* [...] */);
    $result = $db->fetchAll('SELECT * FROM huge_table');
    $cache->save($result, 'myresult');
} else {
    // cache hit! shout so that we know
    echo "This one is from cache!'n'n";
}
print_r($result);

我的库可以与APC,Memcache,Memcached和PHP共享内存一起使用:PHP Memory Cacher