• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cache wildcards - Find / delete all cache starting with prefix


I'm working on a project that relies heavily on cache for performance gains. All the cache created is intentionally set to expire in a DECADE and deleted upon user/system action. When there are a few cache keys to handle with a few dependencies between the cached objects, there is no problem... Although, the more cache keys and dependencies there are to handle, the harder it gets to manage it and at some point, it creates inevitable bugs.

CodeIgniter offers some basic ways to get and delete single cache objects when the key is known (https://codeigniter4.github.io/userguide...ching.html).
--> Regarding the project I'm working on, the cache I create is named manually with some identifiers from the database to ensure unique cache keys. So, the hassle comes when wanting to delete it as I need to get the identifier back from the database.

A solution to this would be to add a method to find or delete all cache of which keys are starting with a given prefix.

PHP Code:
// find all cache starting with `prefix_`
// would return an array: ["prefix_...", "prefix..."];

// delete all cache starting with `prefix_`

I've seen that there is a `$prefix`attribute that can be set to prefix any created cache key, it could be merged somehow with the `clean()` method that removes the entire cache.

PHP Code:
// This would remove all the cache starting with "prefix"

This would help greatly remove the load on the database (in my case) as well as maintaining cache more easily.

That's it, hope to have been clear!

PS: I've been using CodeIgniter4 for a few months now and I'm quite fond of it! Thanks for all your work.

Messages In This Thread
Cache wildcards - Find / delete all cache starting with prefix - by yassine - 10-19-2020, 09:16 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.