Programmaticaly clear webpage cache |
Hi
I am using webpage caching and it works perfect. But I want to be able to clear the cache on a per page basis. Is there a way of doing this without manually search and delete the file?
Why do you need to delete?
There is no easy way. You need to write code for it.
See cachePage() in system/CodeIgniter.php In CI3 there is a method to delete cache: $this->output->delete_cache() https://codeigniter.com/userguide3/gener...ing-caches But it seems there is no method in CI4: https://codeigniter4.github.io/CodeIgnit...ing-caches
Thanks.
One last question. Is there some sort of table somewhere which matches the cache file with the right url? I assume CI doesnt loop through all the cached files to see which one to use.
Cached data does not have URI, CI generates a cache key from URI.
See https://github.com/codeigniter4/CodeIgni...r.php#L762
I understand.
But how does CI knows which file to render? The filenames are random.
They are not random.
The cache key (= filename) is the md5 hash for the current URI.
Thanks,
Solved it by doing: PHP Code: @unlink(WRITEPATH.'/cache/'.md5(base_url($slug))); Whenever I update a page |
Welcome Guest, Not a member yet? Register Sign In |