Welcome Guest, Not a member yet? Register   Sign In
Cache-Control header always prepend "no-store, no-cache, must-revalidate"
#1

(This post was last modified: 08-22-2023, 06:29 AM by parisiam.)

I'm using PHP 8.1 and CI 4.3.7
I've built a filter to change HTTP caching (Cache-Control header) for some pages of my website.

PHP Code:
class CacheFilter implements FilterInterface
{
    public function before(RequestInterface $request$arguments null)
    {
        // Get the response instance
        $response service('response');
        // $response = \Config\Services::response();

        // Define caching options
        $options = [
            'public',
            'max-age'  => HOUR,
            's-maxage' => DAY,
        ];

        $response->setCache($options);
    }
... 

I apply the filter (alias is 'cache') to the routes :
PHP Code:
$routes->get('page''PageController::view', ['filter' => 'cache']); 

I always end up with this values for Cache-Control in the response header:
Code:
Cache-Control: no-store, no-cache, must-revalidate, public, max-age=3600, s-maxage=86400
# OR:
Cache-Control: no-store, no-cache, must-revalidate
Cache-Control: public, max-age=3600, s-maxage=86400

The expected response is:
Code:
Cache-Control: public, max-age=3600, s-maxage=86400
because `setCache()` deletes existing values for Cache-Control before applying new ones.

I tried several browsers with the same result. I tried to follow CI code up to codeigniter.php and everything seems right.

So what's the problem ?
Anyone has ever seen this ?
Reply


Messages In This Thread
Cache-Control header always prepend "no-store, no-cache, must-revalidate" - by parisiam - 08-22-2023, 06:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB