(Template) Caching
#1
Posted 30 January 2011 - 10:44 AM
I don't know how caching is implemented but would it be possible to have some sort of 'on update delete cached file' functionality?
#2
Posted 30 January 2011 - 10:46 AM
does it 'fail'? Or the cache file has still the same time properties? (because the save process may do a new cahce file in the very saving process)
Or how it's site reacting (the cache file actually may be deleted/rewritten on the first visit of updated page)?
#3
Posted 30 January 2011 - 12:11 PM
#4
Posted 31 January 2011 - 09:47 AM
https://github.com/r...06c058e3ee4e76f
#5
Posted 12 August 2011 - 01:43 PM
Might be good for simple module, but these could be settings also on template -> cache tab? What you guys think? I think that most beneficial page to cache is homepage, but not sure how to do it now, since it usually pulls data from many other pages.
PS: I really like the possibility to avoid cache with predefined post & get variables! Though it might be good idea to always disable cache, if there is "CommentForm_submit" POST variable available. Or does that open doors for DoS-attack?
#6
Posted 12 August 2011 - 04:51 PM
1. Use low cache times with the current system on pages you don't want to risk having old content (seconds or minutes rather than hours).
2. Or, Set the cache to wipe entirely on every page save.
The second option was what PW1 used. It can be done without much overhead because PW's cache looks in a "lastgood" file that has a mtime timestamp of when the cache was last considered good. Any cache files older than the date of that file are considered expired, whether they exist or not. So PW can uncache everything just by updating the mtime of that one file.
Given the above, it would be relatively easy for me to add an option to the template cache settings that says "When a page using this template is saved, clear: 1) this page's cache file; or 2) cache files from all pages." Anything beyond that could involve significantly more overhead, short of major changes to the current CacheFile class (which can certainly be done in the future).
#7
Posted 12 August 2011 - 05:46 PM
#9
Posted 15 August 2011 - 07:16 AM
#10
Posted 15 August 2011 - 08:27 AM
When I save a page:
1. Expire the cache for the saved page only.
2. Expire the cache for all pages.
Being able to specify that at the template level will provide a lot of flexibility.
#11
Posted 31 August 2011 - 06:48 AM
So instead of clearing whole cache it would be beneficial to have third option:
3. Expire the cache for the saved page and it's parent page.
I think that would be perfect in many situations, since that would allow to cache normal news-front template, since cache expires when someone edits/adds/removes news-item pages under that page. What do you think?
#12
Posted 31 August 2011 - 07:28 AM
What would be great in theory is if there was some way to track wherever a $pages->find call (or other such bits of code) is made in a template file that returns in it's results the page you're saving, as well as any pages that use InputPageSelect (and other such field types) and clear the cache for those pages as well - so basically any page that makes use of the data in the page you're saving should have it's cache cleared. Unfortunately that's impossible in practice for the template file side of things (should be do-able for fields) unless you to a preg_match call on every template...
...maybe that wouldn't be so hard to do actually...? It would require looking for any code inside PHP tags that's selecting pages to list and working out which ones relate to the current page you're saving.
Actually no, I think that would get quite messy and depending on the number of templates could take a bit of time. It also wouldn't be fool-proof - the minute you start putting common template bits into other files that you might include that PW doesn't know about (think header.inc, but yourname.inc <- PW wouldn't know that even existed).
So yeah, ignore my train of thought
#13
Posted 31 August 2011 - 09:39 AM
Pete those are great ideas about locating all the pages with references to the current and clearing those as well. Though I'm afraid to go there because the only way to really guarantee that a site is up-to-date is to expire the entire cache. We can track some things (like page references) but not others. So I worry about the ambiguity of any cache clearing options that involve an unknown set of pages ahead of time. Doing so may make some people think that PW may be smart enough to figure out everything that needs to be cleared.
If there is one thing that causes confusion among clients, it's always caching, in my experience.… Client says:
I accidentally misspelled Shilo Toilolo's name in our press release. I went and fixed it right away, but just got a call from the CEO that it says SHITO TOILETO on our homepage! Help!
I respond "go save the homepage, or just wait an hour, it's on a cache". I've dealt with so many of these support calls in the past, that I tend to use the cache sparingly.
A possible 4th option would be one that Antti mentioned earlier, which would be to provide an InputfieldPageListSelectMultiple that lets you specifically select all the pages that should be cleared. While I'd rather make it "clear pages using these templates", the truth is that clearing specific pages (rather than pages using specific templates) is quite a bit simpler to implement in the current system. Though I'm going to toy around with the current cache system sometime to see if there might be a way I can get that per-template cache clearing.
Caching is always a compromise… my opinion is that most people should start with no caching, and only turn it on when they find they need it. And if they find they need it, they should take a close look at the MarkupCache too. But I'll work to expand the caching options, as I think these open a lot of doors to PW's use in high traffic sites.
#14
Posted 31 August 2011 - 09:49 AM
I guess I've got a few scenarios in my head, but we'd need to jot down all possible scenarios to get this right. Problem is when you start clearing the cache on entire sections of the site then like you say, you may as well clear the whole thing! Maybe a better way would be to have a per page or per template option to stop a page and it's children, or evey page using a template from being cleared from the cache and approach it from that angle? Clear the cache for everything but the pages/templates you specify when a page is saved? Might be less hassle, I don't know - might also be less intuitive but I was thinking that you probably know of sections/pages that, once they're up on the site, will rarely/never change or certainly that they shouldn't have an impact elsewhere.
#15
Posted 21 September 2011 - 09:15 AM
The second option was what PW1 used. It can be done without much overhead because PW's cache looks in a "lastgood" file that has a mtime timestamp of when the cache was last considered good. Any cache files older than the date of that file are considered expired, whether they exist or not. So PW can uncache everything just by updating the mtime of that one file.
It would be very nice to know how often our clients save their pages. I think that it is pretty rare operation on many sites (not even every day), and some sites edit/add content few times in hour. I think that many times even on actively edited sites the "wipe whole cache" could be very good solution (knowing the fact that wiping the whole cache is "cheap" operation - and doing this only on templates that gets pulled through API - usually something like news, events etc). Don't know how much overhead it gives to then always write cache files over and over again on big sites (over thousand pages)? Or is it always cheaper way than letting pw to query db? (of course this depends also how popular the site is - if pages get very few views then we can forget whole caching
#16
Posted 21 September 2011 - 12:47 PM
When page is saved:
- Clear the page's cache (default)
- Clear the entire site's cache
- Clear the page's cache and it's parents (including homepage)
- Clear specific pages (with page list selection)
- Don't clear anything
Attached is a screenshot with the #4 option selected.
In ProcessWire, using the cache is definitely not required. I leave it off for smaller or lower traffic sites, and then use it only on some templates with higher traffic sites. But now that there are more clearing options, I may start using it a lot more. But my goal is always to keep ProcessWire fast whether you have the cache turned on or not. But there's no doubt that caching can make a big difference on pages where you are performing heavy operations.
#17
Posted 21 September 2011 - 01:28 PM
@somartist | modules created | support me, flattr my work flattr.com
#18
Posted 21 September 2011 - 01:39 PM
#19
Posted 21 September 2011 - 02:05 PM
@somartist | modules created | support me, flattr my work flattr.com
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users













