Caching has been added to the RGraph forumWritten by Richard Heyes, on 12th August 2022
This may be interesting to you - I've just added caching to the RGraph forum. Two types have been added:
- HTTP caching headers
- Server-based pre-rendering
HTTP caching headers
http headers for caching was an easy win - simply
add the relevant
http headers and browsers will
attempt to cache the response (ie the page) that the
server sends. The headers that have been added are as
Cache-Control: public, private, max-age=604800 Expires: Fri, 19 Aug 2022 09:56:47 GMT
So the response is cached for a week and can be cached by your browser and also by other caches too (eg ones at your ISP or other intermediaries).
This is a bit more interesting and a little bit
more involved than simply adding some extra
headers to the response. What is done is a script
that runs every so often makes a
http request for
the forum pages (the ones that are closed) - the
resulting output is stored in a file on disk.
html page that's written to disk is
exactly what you see when you request the page with
Then, when you request a forum post (one that's closed), if it's in the cache it gets sent to your browser instead of the page being built from the contents of the database. So there's less load on the database (something I'm sure the ISP will thank me for). The cache is cleared and then the pages are re-cached every four hours by a cron job (a scheduled task).
If you're thinking of employing this type of
caching then you need to ensure that the
makes up the page doesn't change. If it does then you
could end up with stale, cached copies of your pages
being shown instead of up-to-date copies.