![]() |
Programmaticaly clear webpage cache - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Programmaticaly clear webpage cache (/showthread.php?tid=87969) |
Programmaticaly clear webpage cache - sjender - 06-28-2023 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? RE: Programmaticaly clear webpage cache - kenjis - 06-29-2023 Why do you need to delete? RE: Programmaticaly clear webpage cache - sjender - 06-29-2023 For when the content changes before cache expiry RE: Programmaticaly clear webpage cache - kenjis - 06-29-2023 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/general/caching.html#deleting-caches But it seems there is no method in CI4: https://codeigniter4.github.io/CodeIgniter4/general/caching.html#deleting-caches RE: Programmaticaly clear webpage cache - sjender - 06-29-2023 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. RE: Programmaticaly clear webpage cache - kenjis - 06-29-2023 Cached data does not have URI, CI generates a cache key from URI. See https://github.com/codeigniter4/CodeIgniter4/blob/b1b5544a75e2ed1637fed7ab74ee3d4de604b8f9/system/CodeIgniter.php#L762 RE: Programmaticaly clear webpage cache - sjender - 06-29-2023 I understand. But how does CI knows which file to render? The filenames are random. RE: Programmaticaly clear webpage cache - kenjis - 06-29-2023 They are not random. The cache key (= filename) is the md5 hash for the current URI. RE: Programmaticaly clear webpage cache - sjender - 06-29-2023 Thanks, Solved it by doing: PHP Code: @unlink(WRITEPATH.'/cache/'.md5(base_url($slug))); Whenever I update a page RE: Programmaticaly clear webpage cache - kenjis - 06-29-2023 I found this post: https://forum.codeigniter.com/showthread.php?tid=76772 |