从laravel 4中删除分页缓存

时间:2014-02-11 15:38:20

标签: php caching pagination laravel-4

我正在使用此代码缓存我的分页

Album::remember(3)->paginate(20);

但我不知道如何在到期时间之前从分页中删除缓存。有人可以帮忙。

1 个答案:

答案 0 :(得分:1)

您通常不会“忘记”数据库缓存,因为您需要知道用作密钥的哈希。

您可以使用getCacheKey()方法检索它(它的定义如下):

/**
 * Get a unique cache key for the complete query.
 *
 * @return string
*/
 public function getCacheKey()
 {
  return $this->cacheKey ?: $this->generateCacheKey();
 }

这样的东西
$results = Album::remember(3)->paginate(20);
$key = Album::getCacheKey();
Cache::forget($key);

可以工作,但我承认我从未使用过这个程序,我倾向于为remember()方法分配一个自定义密钥并使用它来忘记它:

Album::remember(3, 'pagination')->paginate(20);
Cache::forget('pagination');
相关问题