CodeIgniter Forums
Delete Web Page Cache in CI4 - Printable Version

+- CodeIgniter Forums (
+-- Forum: CodeIgniter 4 (
+--- Forum: CodeIgniter 4 Support (
+--- Thread: Delete Web Page Cache in CI4 (/showthread.php?tid=76772)

Delete Web Page Cache in CI4 - benjaminbellamy - 06-18-2020

I am using Full Page caching:

It works perfectly.

Now I need to delete a specific page cache.
CI3 has a delete_cache() method to do that but I cannot find one for CI4:

Am I missing something?


RE: Delete Web Page Cache in CI4 - dave friend - 06-18-2020

The Cache class has a delete method.

You can get a reference to the Cache class anytime using

PHP Code:
$cache Services::cache(); 

The delete method takes a string argument that is the cached item name.

PHP Code:

The hard part, for which I have no answer, is how do you determine the value of $key.

RE: Delete Web Page Cache in CI4 - jreklund - 06-19-2020

It's based on a md5 hash of the full url of the page. This example are based on if you have cacheQueryString set to false and run in the Controller.

PHP Code:
// Get the current page url automatically, in case you want to store it somewhere.
$uri $this->request->uri;

$name = \CodeIgniter\HTTP\URI::createURIString($uri->getScheme(), $uri->getAuthority(), $uri->getPath());


// Get the current scheme and authority (includes domain) automatic, and append custom string.
$uri $this->request->uri;

$name = \CodeIgniter\HTTP\URI::createURIString($uri->getScheme(), $uri->getAuthority(), 'some/path');


// Build your own, so you can delete it somewhere else.

echo md5(\CodeIgniter\HTTP\URI::createURIString('http''''/'));

echo md5(\CodeIgniter\HTTP\URI::createURIString('http''''some/path')); 

You can of course specify the url manually if you like, you don't need to use createURIString. As long as the url matches, it will work.

The md5 generated are the $key in the above post.