$new = $this->memcache->get("posts");
if(empty($new)){
// Get the new posts
$new = Posts::getNow("10");
// Save them in memcache
$this->memcache->set('posts', serialize($new), 0, 60*3); // Cache time is 3 min
// If we found them in cache - load them from there
} else {
// Get data from memcache
$new = unserialize($this->memcache->get("posts"));
}
如果缓存中存在数据,则代码非常简单,如果不再获取它们。有趣的是,有时当我查看网站时,div 是空的并且没有数据,但是当我重新加载页面时,那里有数据。当缓存被擦除时,我对站点的看法是否可能?