pulpmedia / pulpcache
一个简单的缓存类
dev-master / 1.0.x-dev
2015-09-17 10:16 UTC
Requires
- php: >=5.3.2
This package is auto-updated.
Last update: 2024-09-20 23:59:07 UTC
README
#pulpCache
一个简单的缓存类
##使用方法
###初始化
要初始化一个新的缓存,只需创建一个新的 PulpCache 实例
$cache = new pulpCache();
您可以将一些选项作为数组添加
cache_dir: Target directory for the cache (default ./cache)
config_file: Name of the Cache Configfile (defailt config.json)
expire_at: TimeStamp at which the Cache will be marked as old next (will be overwritten with each "save")
cache_name: Name of the Current cached file
ttl: Time to live (in Seconds). This will be used to set "expire_at" (current time + ttl). Default: 86500 (One Day)
#####示例 <?php
require_once(dirname(__FILE)) . 'pulpcache/pulpCache.php');
$config = new array('cache_dir' => '/path/to/cache/dir',
'cache_name' => 'file_to_cache',
'ttl' => 3600
);
$cache = new PulpCache($config);
###缓存
要实际缓存内容,您应使用以下 3 个方法
hasCache() : Returns true if there is cached content available
getCache(): Returns the cached Content
saveCache($content): Saves $content
#####示例
<?php
require_once(dirname(__FILE)) . 'pulpcache/pulpCache.php');
$config = new array('cache_dir' => '/path/to/cache/dir',
'cache_name' => 'file_to_cache',
'ttl' => 3600
);
$cache = new PulpCache($config);
$content = "";
if(!$cache -> hasCache() ){
...
... Fill $content wicth Content
...
$cache->saveCache($content);
} else {
$content = $cache -> getCache();
}
echo $content