Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Remove static pages from cache on unpublish


Go to End
Reply


15 Posts   3347 Views

Avatar
martimiz

Forum Moderator, 1132 Posts

14 August 2009 at 1:18am

Hi
I'm using StaticPublisher for a couple of sites and all works well. I have a bit of a problem though: cached pages are not removed when they are unpublished or deleted, not even on rebuilding the whole cache. So if someone has a page bookmarked it will still be found. Can anyone confirm this, or is it me doing something wrong? Is there some way I can fix this?

Avatar
Pigeon

Community Member, 243 Posts

14 August 2009 at 2:50am

Hi,

I use the static publisher quite a bit and it does have quite a few limitations like the one you have outlined here.

I haven't had time to properly modify / customise the publisher but i would imagine creating a onBeforeDelete() method for the StaticPublisher class would be a good start.

Hope that helps.

Avatar
martimiz

Forum Moderator, 1132 Posts

14 August 2009 at 3:06am

Thanks - I admit I was secretly hoping that someone had already done the work :-) Anyway - maybe some SiteTree Decorator equivalent to FilesystemPublisher that has an onAfterUnpublish() method..?

Avatar
Pigeon

Community Member, 243 Posts

14 August 2009 at 3:39am

Yes, i was hoping someone would have done lots of this too! (and i'm sure they have) - the only modificaltion i have made is adding '<!-- Cached '.date("l jS \of F Y h:i:s A").' -->' to the cached files so i know when i'm seeing cached and when I'm not.

There is quite a bit of work that could go on with the static publisher. Eg: if there is dynamic content on the home page (say latest news item) when a new news item is created, the home page doesn't get republished. Also, the fact that the buildcache routine doesnt actually delete the old cache [because the method is looking for a folder in /cms/ called cache. Highly frustrating as it means that I have to empty the cache folder for the site's users when they want a re-cache.

I did do some searching for an 'onAfterUnpublish()' method when i saw your question; but i couldn't find it [http://api.silverstripe.org/cms/publishers/StaticPublisher.html].

If you find a solution, please let me know!

Avatar
martimiz

Forum Moderator, 1132 Posts

14 August 2009 at 6:39am

Edited: 14/08/2009 6:40am

As for buildcache: '../cache' is hardcoded in cms/dev/RebuildStaticCacheTask.php - line 49 and further.

if($removeAll && file_exists("../cache")) {
   echo "Removing old cache... \n";
   flush();
   Filesystem::removeFolder("../cache", true);
   echo "done.\n\n";
}

The real destination folder for the cache is stored in the $destFolder property of the FilesystemPublisher class, where it can't be reached(?). - line 29:

function __construct($destFolder, $fileExtension = null) {
   if(substr($destFolder, -1) == '/') $destFolder = substr($destFolder, 0, -1);
   $this->destFolder = $destFolder;

As a quick'n dirty fix, I edited existing code, doubled the destFolder as a public static $myDestFolder in FilesystemPublisher, and then requested it as FilesystemPublisher::$myDestFolder in RebuildCache(). This is obviously not the preferred way, but solves one problem for the time being :-)

Avatar
Willr

Forum Moderator, 5513 Posts

14 August 2009 at 3:21pm

We are currently working on a few updates to the build cache tool to make it smarter. martimiz I think you are on the right track with cache folder being hardcoded, that shouldn't be like that (though we always use /cache/ as convention).

Avatar
martimiz

Forum Moderator, 1132 Posts

14 August 2009 at 8:06pm

Thanks willr, that would be great as this is great extension to the CMS :-)

By the way - I Remembered a temp fix for the problem of menus not properly highliting on static pages (see: http://silverstripe.org/customising-the-cms/show/263809?showPost=266813&start=0 - please ignore the problem I had with multiple posts)

@Pigeon: as for the issue with the homepage: this is something you could maybe address from your page's pagesAffectedByChanges() function, by always adding the homepage to the $urls...

Avatar
Pigeon

Community Member, 243 Posts

14 August 2009 at 11:13pm

Ah, nice tip. I just haven't had time to implement the caching as affectively as i could.

I never really realised what pagesAffectedByChanges() did :P

So, if i add a pagesAffectedByChanges() method to my news article / holder code pages and say 'home', would that work?

@willr: the hard coded folder is /cms/cache/ i believe as i use /cache/ and it doesn't delete the files.

Go to Top