CodeIgniter Forums
How to retrive cacheKey generated ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: How to retrive cacheKey generated ? (/showthread.php?tid=90976)



How to retrive cacheKey generated ? - ALTITUDE_DEV - 05-30-2024

Hello here, 


I have tried several caching methods on my CI 4.5 project, and the method `$this->cachePage(2500);` is the most efficient (less than 40ms). My question is as follows:

So, I am performing caching with: `$this->cachePage(TIME);`
How can I get the randomly generated cache key created by the CI caching system?

we need this key: 
[Image: dTbxhHp.png]

The key, something like in MD5, I would need it to be able to create a function to delete the cache of the concerned page.

Thank you for your help.


RE: How to retrive cacheKey generated ? - kenjis - 05-30-2024

See https://github.com/codeigniter4/CodeIgniter4/blob/dcbcf3828d350de7036a86f52a7e5127c969298e/system/Cache/ResponseCache.php#L74-L87


RE: How to retrive cacheKey generated ? - ALTITUDE_DEV - 05-30-2024

Hi thanks for reply
I have make this and is working Wink 

PHP Code:
/**
* getCacheKey
* @var url
* @var get/post
*/
if (! function_exists('getCachedKey')) {
    function getCachedKey($uriSend$method){
        $request  = \Config\Services::request();
        if($method == false){
            $methodReq $request->getMethod();
        }else{
            $methodReq $method;
        }
        if($uriSend == false){
            $uri $request->getUri();
        }else{
            $uri = new \CodeIgniter\HTTP\URI($uriSend);
        }
        $query '';
        return md5($methodReq ':' $uri->setFragment('')->setQuery($query));
    }




RE: How to retrive cacheKey generated ? - ozornick - 05-30-2024

You can use the forum search
https://forum.codeigniter.com/showthread.php?tid=90893


RE: How to retrive cacheKey generated ? - ALTITUDE_DEV - 05-30-2024

(05-30-2024, 05:10 AM)ozornick Wrote: You can use the forum search
https://forum.codeigniter.com/showthread.php?tid=90893

If I ask the question, it is because the answer has not been found. I had actually found this function before even posting a request on the forum Wink