gigabyte / cache

PHP 缓存库

dev-master 2016-02-18 14:27 UTC

This package is auto-updated.

Last update: 2024-08-27 08:29:26 UTC


README

您可以通过从 GitHub 下载包或通过 composer 安装来安装 Extreme PHP Cache。我鼓励您使用后者

{ 
  "require": {
    "gigabyte/cache": "dev-master"
  }
} 

这个 PHP 库可以轻松地将任何 PHP 对象缓存到缓存中,具有特定的参数。目前它只支持文件系统缓存。

基本用法

namespace gigabyte\cache;

$cache_config = new CacheConfig();
$cache_config->setCacheModule('search result')
        ->setIntervalInDay(2)
        ->setCacheFilter(array('serach' => $serach, 'param1' => $value1, 'param2' => $value2));
$cache = CacheFactory::createFileCache($cache_config,"mycache/");
if ($cache->checkCache()) {
    $search_result = $cache->readCache();
} else {
    //calculate $search_result
    $cache->writeCache($search_result);
}