Panel shows cached version of page after changing content

#1

I’m running the latest version of Kirby, 3.0.3. Whenever I save anything in the panel, it falls back to a cached version of the page while the content file gets edited correctly. I’ve tried to reïnstall kirby and remove all plugins temporarily without result.

The only way to work in the panel currently is by having inspector opened with ‘disable cache’ enabled.

What could be the cause of this?

#2

Maybe related to this?
https://getkirby.com/docs/guide/troubleshooting/panel#opcache

#3

Gave it a try, but doesn’t work.

#4

I have similar problem after setting browser cache in my .htaccess file (I followed this guide).

#5

I’m using similar htaccess caching settings. The issue persists though after commenting the settings.

#6

I have to say that I can’t think of more pointers - seems like it is really connected to your server setup.

#7

I’m running into this myself now. Content is only updated when dev tools is open and caching disabled.

#8

Any chance your server is emitting Cache-Control headers? Or, if you’re behind a CDN that automatically caches pages, are you making sure api/panel requests are not being cached?

For example, I emit Cache-Control headers like this so Cloudflare knows what to cache and what to not.

'hooks' => [
    'route:before' => function ($route, $path, $method) {
        $kirby = kirby();
        $query = Url::query() ?: '';
        
        $response = $kirby->response();
        
        $shouldCache =  'GET' === $method
                        && $kirby->option('cache.pages.active')
                        && !Str::startsWith($path, 'api', true)
                        && !Str::startsWith($path, 'panel', true)
                        && !Str::contains($query, 'token=', true);
        
        if ($shouldCache) {
            $response
            ->header('Cache-Control', 'max-age=1800, must-revalidate') // 30 minutes (60 * 30)
            ;
        }
        else {
            $response
            ->header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
            ->header('Expires', 'Fri, 01 Jan 1990 00:00:00 GMT')
            ;
        }
    }
],

But if you’re setting headers in your Apache/Nginx config, then you’ll probably want to make adjustments there.

#9

@neildaniels Ah, thanks, that reminded me that I had actually set Expires HTTP headers in my .htaccess recently for testing and completely forgotten about it :see_no_evil:. All good now.

#10

Updated troubleshooting guide.