Jump to:

23376 Posts in 18295 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Remove static pages from cache on unpublish

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

Page: 1 2
Go to End
Author Topic: 3080 Views
  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Remove static pages from cache on unpublish Link to this post

    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?

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Remove static pages from cache on unpublish Link to this post

    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.

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: Remove static pages from cache on unpublish Link to this post

    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..?

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Remove static pages from cache on unpublish Link to this post

    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!

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: Remove static pages from cache on unpublish Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Remove static pages from cache on unpublish Link to this post

    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).

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: Remove static pages from cache on unpublish Link to this post

    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...

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Remove static pages from cache on unpublish Link to this post

    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

    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.

    3080 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.