Hi.
I have a page which takes a long time to load (it's an asset listing that compiles information from a lot of other asset listings – takes about 60 seconds), but doesn't change very often. Is it possible to automatically load that content into the cache on a regular basis (during the night, for example), so that no user has to wait the initial load time?
Regards,
David C
You could run a cronjob under Linux that uses wget to retrieve a copy of that page. This will cause Matrix to recache the page.
A great idea, thanks.
Will there be any problem with the current cache expiry time of 24 hours (86400 secs)? It seems there might be a problem where you couldn't be sure you were loading a new page or still using yesterday's cache. Would setting the cache expiry back 1/2 an hour or so be sensible?
David C
True. You might want to set it to 23 hours or similar.
From my experiences with working with the cache manager, you could probably add the no-caching extension to the URL that is wget'd; this in effect clears the cache for that particular asset, ensuring the most recent version is obtained and re-cached.
In version 3.4: add '?no_cache=1' to the URL's query string. In version 3.6: add '/_nocache' to the URL itself, or whatever is set in your main.inc config file.
[quote]From my experiences with working with the cache manager, you could probably add the no-caching extension to the URL that is wget’d; this in effect clears the cache for that particular asset, ensuring the most recent version is obtained and re-cached.
[right][post=“7465”]<{POST_SNAPBACK}>[/post][/right][/quote]
I’m not sure that’s what the no_cache option does: Essentially it just bypasses the “Is this cached?” check, but it doesn’t clear/recache the page.
The no-cache option WILL NOT cache a new version of the asset.
The problem you will have is day 1 the cache expires at 23:30, and if someone visits the page at 23:35 they cache it, then day 2 it expires at 23:05… and very quickly your midnight cron job becomes useless.
The cleanest solution I can think of is that you would have the "clear cache" function in Matrix available to use in Matrix cron jobs and triggers. You also need a function that caches a page.
You could then have a trigger that fires when you edit a page, which clears the cache for that page and then loads the new page into cache. For asset listings that you never edit, you could either have a trigger on the assets that they list so when the metadata (eg title) for those pages are changed, or a page is added or deleted, the cached asset listing is updated. Alternatively you could set a cron within Matrix to run each night that clears the cache for that page and reloads it.
That's not so bad for us, because this isn't the sort of page that people are going to look at all that often (and not at 2 in the morning). However, it's definately a concern for a more generic solution.
I'll set my timeout to 23:45 and see how it works.