Skip to content

Enhance cache writing with last modified timestamp#40

Draft
diplix wants to merge 1 commit intogetkirby:mainfrom
diplix:patch-1
Draft

Enhance cache writing with last modified timestamp#40
diplix wants to merge 1 commit intogetkirby:mainfrom
diplix:patch-1

Conversation

@diplix
Copy link
Copy Markdown

@diplix diplix commented Nov 28, 2025

add $page->modiefied() timestamp to cache files. this way the webserver can return the actual last-modified date (instead of the cache write date), when serving cached files.

Description

by adding

@touch($cacheFile, $page->modified());

cache files get an accurate modified date, tested on my site:

before:

ubuntu@kirby:/var/www/kirby$ curl -I https://wirres.net/articles/der-buchhalter-und-ein-baum
HTTP/2 200
last-modified: Thu, 27 Nov 2025 12:47:15 GMT
etag: "9a94-64492e9a3ab02"
accept-ranges: bytes
content-length: 39572
vary: Accept-Encoding
x-content-type-options: nosniff
cache-control: no-cache
content-type: text/html
date: Thu, 27 Nov 2025 13:43:28 GMT
server: Apache/2.4.58 (Ubuntu)

after

ubuntu@kirby:/var/www/kirby$ curl -I https://wirres.net/articles/der-buchhalter-und-ein-baum
HTTP/2 200
last-modified: Sun, 16 Nov 2025 02:57:52 GMT
etag: "9a94-643ad6586cc00"
accept-ranges: bytes
content-length: 39572
vary: Accept-Encoding
x-content-type-options: nosniff
cache-control: no-cache
content-type: text/html
date: Thu, 27 Nov 2025 13:43:50 GMT
server: Apache/2.4.58 (Ubuntu)

add $page->modiefied() timestamp to cache files. this way the webserver can return the actual `last-modified` date (instead of the cache write date), when serving cached files.
@diplix
Copy link
Copy Markdown
Author

diplix commented Nov 29, 2025

hm, i think i have to work on this more. since some pages or templates are not modified, if if they change, this might lead to strange effects. i.e. my overview page, that liste recent articles in reverse chronological order, was not reladed, because the browser thought (rightfully so), that the page was modified long ago and does not need to be reloaded.

this can be worked around by only including certain templates, but that is not generalizable.

so please don’t merge this PR until i had more time to think about it.

@bastianallgeier bastianallgeier marked this pull request as draft December 1, 2025 09:23
@bastianallgeier
Copy link
Copy Markdown
Member

I've converted it to a draft. Feel free to change it again as soon as you feel that it is ready.

@lukasbestle
Copy link
Copy Markdown
Member

I had the same thought reading your PR description. We would basically need to make a dynamic list of all models that are used in the response and use the latest modified date from all of these models. It would be possible to auto-detect used models in the Kirby core (e.g. by logging when a content field of the respective model is returned and therefore likely to be printed). But this is out of scope of Staticache as the plugin cannot collect this information.

Dynamic Kirby page responses (without using Staticache) don't contain the Last-Modified header at all. So an alternative solution could be to configure Header unset Last-Modified in Apache to omit the header if it causes actual problems in the setup. If it doesn't, I'd probably rather keep the auto-generated one based on the cache as it helps with browser caching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants