【发布时间】:2016-05-11 02:17:14
【问题描述】:
在 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
}
}
【问题讨论】:
-
无法添加自定义属性,但
mtime有什么问题? -
如果每个 var 缓存具有相同的超时时间,我可以使用 mtime。如果没有,我必须另寻出路。
标签: php file caching filetime cache-expiration