Prevent cache on ajax snippet

I’m caching a page for faster loading, then loading a calendar widget using ajax so the current day can change. However, Kirby seems to be grabbing a cached version of the calendar widget, and then loading that via ajax on every page load. Unfortunately, this still leads to an old current-day showing until the cache gets cleared.

I’ve added the snippet name to the cache.ignore array but it doesn’t seem to prevent it from caching. Should I be using a different approach? Thank you!

u can only cache ignore complete pages…

if you were still to cache some part of the site, you would have to write some sort of file caching yourself for all sections except for your calendar…

i have done this kind of thing for one pagers where the contact form was not supposed to be cached … so…

Thank you @carstengrimm! So does this mean you would expect all my snippets and template.json files to be cached by default if I have caching on?

I think I may have solved it by adding a timestamp to my json request as was stated elsewhere in the forum. Though I won’t know for sure until tomorrow when the calendar is supposed to change.

if it’s cached the content will be saved as a static html output inside a file… so unless this file is deleted, it won’t load new content…

the file will be deleted once you update the page via panel (or you delete the file manually)

otherwise you can also write a function to clear cache every day

e.g. checking the cache files modified date, and if it’s timestamp is not the current date, it’ll get deleted. and once a visitor comes to the site, it’ll create a new cached version.

1 Like

When using AJAX to fetch content in a “file-cache Kirby setup” I would advise using content representations to fetch your content (as JSON e.g.). This should fix your caching issue afaik.