【发布时间】:2016-06-26 06:36:23
【问题描述】:
我的代码正在从数据库中获取数据。从数据库加载数据大约需要 5 秒。所以我使用 memcached 缓存来缓存数据库数据。所以页面加载大约需要 1 秒。但问题是当我更新数据库中的数据我的网页显示旧的缓存数据。memcache 中是否有任何自动更新机制或如何使用 memcache 显示经常更新的数据。 这是我的代码:
$memcache = new Memcache;
$memcache->connect('localhost',portno) or die ("Could not connect");
$result = $memcache->get('key'. $_SESSION['front_app']['employee_id'].$month.$year);
if(!$result){
foreach ($call_arr as $c) {
$result[] = $a->get_submitted_status($start_date, $end_date,id); /*this fetches data from database*/
}
}
$memcache->set('key'.id.$month.$year,$result);
请帮忙解决这个问题。
【问题讨论】: