在 php 中,我创建了一个缓存文件以存储复杂的结果变量。一个变量,一个缓存文件。干得好。
问题在于缓存的期限。目前我将超时和变量放入文件中,但它没有优化,因为我必须打开文件来检查超时。
我想(如果可能的话)检查文件属性的超时(例如使用函数 filemtime() 上次修改的日期)。我们可以将自定义属性添加到文件中吗?
另一种方法是在文件名中添加超时,不是我最喜欢的解决方案。
[编辑]
final class Cache_Var extends Cache {
public static function put($key, $value, $timeout=0) {
// different timeout by variable (if 0, infinite timeout)
}
public static function get($key) {
// no timeout to get a var cache
// return null if file not found, or if timeout expire
// return var otherwise
}
}