Welcome Guest, Not a member yet? Register   Sign In
Programmaticaly clear webpage cache
#1

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?
Reply
#2

Why do you need to delete?
Reply
#3

For when the content changes before cache expiry
Reply
#4

(This post was last modified: 06-29-2023, 01:12 AM by kenjis.)

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
Reply
#5

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.
Reply
#6

Cached data does not have URI, CI generates a cache key from URI.
See https://github.com/codeigniter4/CodeIgni...r.php#L762
Reply
#7

I understand.

But how does CI knows which file to render?
The filenames are random.
Reply
#8

They are not random.
The cache key (= filename) is the md5 hash for the current URI.
Reply
#9
Wink 

Thanks,
Solved it by doing:
PHP Code:
@unlink(WRITEPATH.'/cache/'.md5(base_url($slug))); 

Whenever I update a page
Reply
#10

I found this post: https://forum.codeigniter.com/showthread.php?tid=76772
Reply




Theme © iAndrew 2016 - Forum software by © MyBB