Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Delete cache entry

Started by Muut Archive 10 years ago · 2 replies · 301 views
10 years ago

Is it possible to delete a single cache entry?
I'm using $cache->save($cache_id, $cacheoutput); to save cache, and I want to be able to delete specific cache entries. (Deleting all cache is far to expensive on resources)

I tried: $delete = $cachedriver->delete($cache_id);
It returns true, but the specific cache keeps being served. (I'm using simple filesystem cache)

Any thoughts on how to implement this if not available?

10 years ago

Solved it by using:

$cachedriver = $this->grav['cache']->getCacheDriver();
$cachedriver->save($cacheid, $cacheoutput);

instead of
$cache = $this->grav['cache'];
$cache->save($cacheid, $cacheoutput); to save cache

I can then delete it using:
$cachedriver = $this->grav['cache']->getCacheDriver();
$cachedriver->delete($cacheid);

10 years ago

Yup, you worked it out already :)

We hope to bring some smarter cache clearing strategies to Grav this year. It's a bit more complex than it sounds because there are implications of a config change having an effect on all pages. but a simple page change should be smart enough to update only that page.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1356 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2954 9 years ago
Archive · by Muut Archive, 9 years ago
3 1120 9 years ago