Cache and Forms

Hello!

I ran into issues with Uniform and Kirby’s cache. Basically, the cache stores entries based on URIs for all HTTP request types. This breaks POST submits because Kirby returns the cached page rather than pushing the request through.

I tried writing a route to add the URI to the cache.ignore array in kirby.php, but then it’s ignored for all HTTP request types, which is the same thing as specifying it in an cache.ignore array in config.php.

My problem with using the cache.ignore array is that my editors can change things on the fly without my knowledge and I’d rather not chase this down for every URL they come up with.

What I’m thinking might be nice are…

a) A way to specify HTTP method types in cache.ignore. Something like:

c::set('cache.ignore', [
    'blog/cow', [ 'POST', 'DELETE' ]
]);

b) A way to specify wildcards in the cache.ignore array. Like:

c::set('cache.ignore', [
    'cat/*'
]);

Or using the Kirby wildcard syntax:

c::set('cache.ignore', [
    'cat/(:all)'
]);

So ultimately, it’d be:

c::set('cache.ignore', [
    'cat/*', [ 'POST', 'DELETE']
]);

Does that make sense?

In the meantime, I’ve disabled cache altogether, which isn’t ideal…

Cheers,
topher

1 Like

That should already be possible: Fix CSS for focus state of e.g. Checkbox, Radiofield etc. · Issue #180 · getkirby/kirby · GitHub

That’s an awesome idea, but the data structure would need to be a bit different (in your example, this would apply to all pages, but I’d prefer setting such things for each page individually. But a different data structure would break existing setups.

Two other options:

  • Only cache GET requests in general, don’t ever cache any other HTTP methods.
  • A separate option (cache.ignore.methods) for globally ignoring HTTP methods (to make the option you proposed clearer and easier to understand).

Cool - I was thinking the methods would be on a per URI basis - something like this:

c::set('cache.ignore', [
    'blog/cow', [ 'POST', 'DELETE' ],
    'smog/how', [ 'POST', 'DELETE' ],
    'cog/chow', [ 'POST' ]
]);

To keep backwards compatibility, you could test if the value exists or is empty and if so apply to all methods.

And it looks like that wildcard commit support change isn’t in 2.0.6. One reason to upgrade!