How does "cache" -> "file" work?

Recently I discovered the Kirby “cache” option (well, there’s a first time for everything).

I tried this setting;

c::set("cache.driver", "file");```

When I visit a page of my Kirby site, I **do** see a new file inside the ```\site\cache\``` folder, cryptically named ```bdabf5842115ca5293461b7b4ffff469``` or something.

Once opened in a text-editor, I can see all the html of the page I just visited - great! :stuck_out_tongue:

But ... if I open a new page, the file above is deleted in the folder and a new one is created (once again with all the html of the page currently opened in my browser).

When I open a third page, also the second one is deleted, etc...


**Is this the way cache should work?**

Why does the folder only contains one page (the most recently viewed one) and not all viewed pages?

At this moment, only the active page is cached, not the previous ones...


<img src="//" width="624" height="116">

_The moment you see a new file, I clicked on a page in my site; the file does change (as does it's content), but I never cache more than one singe file / page..._

It is normal that the cache gets flushed when creating, updating or deleting pages. The reason for that is other pages’ HTML might change as well, e.g. in navigations or on overview pages for blogs etc.

However it is not normal that the cache gets flushed after each page visit. Do you have any code on your site that is modifying any files in the content directory?

However it is not normal that the cache gets flushed after each page visit.

That’s exact what happens :frowning:

The site is just a test set-up, nothing special.

I do understand that the cache is flushed when I change “something” in the back-end, but that’s not the case in this situation.

I simply open the file explorer / finder and navigate through my test-site.

Every time I open a page, the cache kills the existing page and creates a new one.

That way, only the most recently viewed page is cached (and killed, once opening a new page).

It’s rather strange - and I wanted to check if this is “by design” or wrong at all…

This is getting weird…

I tested the cache-option with another site, and this one has different behavior;

  1. When I open the homepage (about 49kb in size) it is cached, yes! :stuck_out_tongue:
  2. When I open some other pages, they are all added in the cache (nothing is deleted).
  3. When I open the homepage again, all files are removed - and the 49kb sized homepage is cached again.
  4. See point 2…

Rather strange, eh?

This is not the expected behaviour, you should in fact see a new file added in the file explorer every time you open a new page in the browser.

See my answer before your response (thanks for the response anyway!).

On another site, the behavior is different;

It caches all pages, but removes them - once I open the homepage…

It’s flushing the cache at all :frowning:

Maybe it’s a plugin, or something… I will remove all non-Kirby things from both test-sites.

Are you sure your homepage code does not contain any code that flushes the cache?

The first site uses AJAX to load the pages, the second one uses a TWITTER stream in the footer.

But that stream is cached (it only updates the timeline from twitter every x-hours).

I will remove all non-relevant things from the set-up, in order to determine what goes wrong.

I don’t see how ajax loading of pages should be responsible for clearing the cache if you don’t do it deliberately. And the Twitter stream is probably also just a piece of javascript code.

Could you test the behavior on a fresh starterkit with just the cache set to true?