ptcong/php-cache-manager

缓存管理库。

此包的官方仓库似乎已消失,因此该包已被冻结。

dev-master 2015-05-29 05:13 UTC

This package is not auto-updated.

Last update: 2020-03-20 16:10:54 UTC


README

  • 用于管理缓存的php库
  • 支持PHP >= 5
  • 支持更多适配器:文件、数组、会话、Memcached、Memcache

变更日志

版本 1.1(2015年1月20日)
  • 重写库
  • 优化文件适配器
  • 添加新的数组适配器(有时用于测试)
  • 不需要类加载器,支持按名称自动加载适配器
  • 删除支持前缀,分组
版本 1.0(2014年4月8日)
  • 首次发布,为图像远程上传库提供快速使用

功能

  • 所有基本功能(设置/ 放入/ 获取/ 删除/ 清空/ 垃圾回收)

要求

  • PHP >= 5 (不使用命名空间,因为仍有一些我使用的托管服务使用PHP 5.2)

支持适配器

  • 文件
  • 数组
  • 会话
  • Memcache(即使值是true/false也总是返回真实值)
  • Memcached

用法

$cacher = ChipVN_Cache_Manager::make('File', array(
    'cache_dir' => __DIR__ . '/cache', // need declare
    'expires'   => 900, // default expires
));
$cacher->set('key', 'value here'); // use default expires
$cacher->set('key', 'new value', 10); // 10 seconds
// you also can use
$cacher->put('key', value);
var_dump($cacher->has('key')); // true


$cacher = ChipVN_Cache_Manager::make('Memcache', array(
    'host' => '127.0.0.1',
    'port' => 11211,
));
// host and port is default, you can make without options
$cacher = ChipVN_Cache_Manager::make('Memcache');
$cacher->put('false_value', false);

// always return real value instead of an empty string or "1" for false, true value.
var_dump($cacher->get('false_value')); // return false

// Cacher don't automatic run garbage collect,
// so you should call this when you want to run garbage
$cacher->garbageCollect();