【发布时间】:2013-01-08 23:20:39
【问题描述】:
我将 Memcached 与我用 CodeIgniter 编写的 PHP Web 应用程序结合使用。我使用这个 Memcached 库https://github.com/tomschlick/memcached-library 当我缓存数据时,我给它的过期时间为 7200,即 2 小时。
模型查询片段:
$result = $this->memcached_library->get(md5($sql));
if (!$result) {
$cursor = $this->db->query($sql);
$result = $cursor->row();
$this->memcached_library->set(md5($sql), $result, 7200);
}
return $result;
酷,这适用于将数据设置到 Memcached 中。我可以看到结果,一切正常。问题在于,将这些数据放入 Memcached 后 2 小时后。
据我了解,在执行 get 函数时,Memcached 应该识别出缓存数据已超过其过期日期,因此将其标记为无效(但不一定将其从内存中删除)。当 PHP 调用获取数据时,它应该返回 false,这反过来会导致我的 if 语句被评估为 true 并重新获取数据并再次将数据设置到 Memcached 中。
但是,似乎 Memcached 从未说过数据无效,并且在 2 小时到期限制之前,相同的旧数据就在那里。如果我在 Memcached 上手动调用 flush(使缓存中的所有数据无效),数据将再次正确设置到 Memcached 中,但我们又遇到了同样的 2 小时过期限制问题。
【问题讨论】:
标签: php mysql codeigniter memcached