This class can be used to store and retrieve cached values from single file. It can store one or more keys in a single cache file. The class can also look up for a given key and retrieve the store value.
It can lock the file during access to prevent corruption, but there is also a sub-class that can be used to access the cache file without locking it.
It can automatically clean-up the least recently used entries to free space
- 纯php实现, 无须任何扩展,支持php4 / 5
- 使用lru算法自动清理过期内容
- 可以安全用于多进程并发
- 最大支持1G缓存文件
- 使用hash定位,读取迅速
require('../secache/secache.php');
$cache = new secache;
$cache->workat('cachedata');
$key = md5('test'); //必须自己做hash,前4位是16进制0-f,最长32位。
$value = '值数据'; //必须是字符串
$cache->store($key,$value);
if($cache->fetch($key,$return)){
echo '<li>'.$key.'=>'.$return.'</li>';
}else{
echo '<li>Data get failed! <b>'.$key.'</b></li>';
}
- 键需要自己做hash处理,最长32位.
- 值必须是字符串。如果要存对象,请自己serialize