$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 が空でデータがない場合がありますが、ページをリロードするとデータがあります。キャッシュが消去されているときにサイトのビューが表示される可能性はありますか?