Welcome Guest, Not a member yet? Register   Sign In
Override page cache functionality
#2

(This post was last modified: 10-24-2020, 05:25 AM by legon614.)

I solved it by overriding cache() in App\Common.php.
If the user is logged in and the user is not under the admin section it should use the dummy handler. They will then never get cache response. The reason for checking if the first URI segment is admin is that I need to clean the cache when an admin edit a page. If it clears the dummy cache nothing happens. It will clean the whole cache which is not optimal but it's ok for me right now.

PHP Code:
if (! function_exists('cache')) {
    function cache(string $key null)
    {
        $session Services::session();
        
        $urlSegments 
current_url(true)->getSegments();
        $useDummyCache $session->logged_in && !in_array('admin'current_url(true)->getSegments());
  
        
// Avoid cached responses if logged in
        $cacheConfig = new Cache();
        $cacheConfig->handler $useDummyCache 'dummy' $cacheConfig->handler;

        $cache Services::cache($cacheConfig);

        // No params - return cache object
        if (is_null($key)) {
            return $cache;
        }

        // Still here? Retrieve the value.
        return $cache->get($key);
    }

Reply


Messages In This Thread
Override page cache functionality - by legon614 - 10-22-2020, 12:14 AM
RE: Override page cache functionality - by legon614 - 10-23-2020, 08:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB