Hossj Hossj - 3 months ago 24
PHP Question

Delete cache on a dynamic page in CodeIgniter

I have reviewed the documentation of CI regarding caching a full page here:
https://www.codeigniter.com/user_guide/general/caching.html

I understand that I can cache a controller/function using the below; anywhere inside that function:

$this->output->cache($n);


However my problem is that for example we have a page:

article/specific/this-is-a-slug

as you can see the


  • controller->article

  • function->specific

  • slug->this-is-a-slug



When I cache the function inside itself, the system automatically detects that slug and creates a new cache for each slug uniquely.

However when I want to delete the cache for that specific slug I do not know how I can do it outside the function itself:

$this->output->delete_cache('/foo/bar');


How can specific that I need only the cache for this specific slug to be deleted?

Answer

You can do it wherever you wish, as long as you know the URI. The string in the delete_cache is the URI.

$this->output->delete_cache('/article/specific/this-is-a-slug');

Caching can be enabled on a per-page basis, and you can set the length of time that a page should remain cached before being refreshed.

Comments