Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Static Publisher - rebuild cache on publishing and home page problem

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

Page: 1 2
Go to End
Author Topic: 5612 Views
  • Anatol
    Avatar
    126 Posts

    Static Publisher - rebuild cache on publishing and home page problem Link to this post

    Hi,

    I just enabled the static publisher. It's a fantastic extension and it was really easy to set it up. I still have a few questions about it, though.

    • - When I create a new page in the CMS I can see that the cached page is created in the /cache/ folder and I can see it in the frontend. The problem here is that other pages are not updated and the new page does not appear in the navigation of other pages. How can I rebuild the cache for all pages when I click on 'save and publish'?
      When I run /dev/buildcache?flush=1 it works and I could set up a cron job to do this once in a while, but I think in my case a simpler solution would be to just initiate the cache rebuild of all pages when I publish the page. How can I do that?

    • - When I create a new page using the php cache control method the page is also added to /cache/ but appears blank in the frontend until I run /dev/buildcache?flush=1 Again, it would help to initiate the buildcache script when publishing.

    • - similar (and regardless of cache control) I would like to rebuild the cache of a single page when a user posts a comment on a page. So the moment a user clicks the post button the page should be re-cached on the server.

    • - I also notice that the home page (index.html/index.php) does not come from the cache (but the .htaccess file looks OK and the index.html/index.php file is in the /cache/ directory). The response header always shows that it's PHP and it takes about five times longer to load the page - about 0.06 seconds for cached pages and about 0.3 seconds for the dynamic home page. And yes, index.php can be used as DirectoryIndex. Any ideas why this page is not cached?

    I would highly appreciate any insights, hints or comments on this.

    Cheers!
    Anatol

  • Anatol
    Avatar
    126 Posts

    Re: Static Publisher - rebuild cache on publishing and home page problem Link to this post

    Hi,

    I'm getting closer to a solution. To re-cache all pages when I press the 'save and publish' button I just had to change the pagesAffectedByChange method (see Page.php) to:

    function pagesAffectedByChanges() {
       return $this->allPagesToCache(); // added line
       $urls = $this->subPagesToCache();
       if($p = $this->Parent) $urls = array_merge((array)$urls, (array)$p->subPagesToCache());
          return $urls;
    }

    What's the best way to call a function when a user adds a comment? I would just like to call a function in Page.php that recaches the current page when a user adds a comment.

    I am also still puzzled why the home page does not come from the cache. I can't see a problem with the .htaccess file but whenever I go to the home page only the PHP page is served.

    I will try to find a solution but I am happy about any suggestion.

    Cheers!
    Anatol

  • Anatol
    Avatar
    126 Posts

    Re: Static Publisher - rebuild cache on publishing and home page problem Link to this post

    Hi,

    one more problem is solved. There is a minor mistake on the .htaccess sample file for the static publisher. That's why the home page did not use the cached page. The '%{DOCUMENT_ROOT}' (see below in green) was missing, and I just did not see it... Here is a snippet:

    # Cached content - homepage
    RewriteCond %{REQUEST_METHOD} ^GET$
    RewriteCond %{QUERY_STRING} ^$
    RewriteCond %{REQUEST_URI} ^/**sitedir**/?$
    RewriteCond %{DOCUMENT_ROOT}/**sitedir**/cache/index.html -f
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* /**sitedir**/cache/index.html [L]

    The .htaccess sample file for the php cache control has the same mistake, and so does the .htaccess sample file for multiple server caching.

    It would be great if someone of the Silverstripe team could correct this.

    Cheers!
    Anatol

  • cliersch
    Avatar
    Community Member
    75 Posts

    Re: Static Publisher - rebuild cache on publishing and home page problem Link to this post

    Hi Anatol,

    I'm just trying to understand how the staticpublisher works. I created the cache folder and the html files using /buildcache. But I'm not able to write the .htaccess file correctly!
    First I copied the example on http://open.silverstripe.com/browser/modules/cms/trunk/code/staticpublisher/htaccess_example_rsyncsingleserver and paste it in my .htaccess file. I changed the /**sitedir**/ statement into my Root Directory on the server (/dev/silverstripe/). But unfortunately the server is still delivering the dynamic sites and not the html version.
    Do you have any Idea what's wrong? Or could you pleas show some example code of your .htaccess file with your developments.
    cheers,
    tiga

  • Anatol
    Avatar
    126 Posts

    Re: Static Publisher - rebuild cache on publishing and home page problem Link to this post

    Hi tiga,

    basically if you follow this information it should work: http://doc.silverstripe.com/doku.php?id=staticpublisher

    Just make sure you add this code to /mysite/Page.php into the Page class.

    Then add

    Object::add_extension("SiteTree", "FilesystemPublisher('cache/', 'html')");


    into your /mysite/_config.php file.

    Then use this .htaccess file , replace /**sitedir**/ with the directory of your Silverstripe installation. So if you access the site through www.mydomain.com/dev/silverstripe/ it should be /dev/silverstripe/ , if it's www.mydomain.com/subdirectory/ it's /subdirectory/.

    Also: make sure you fixed the little mistake in the htmlfile, see my previous post.

    Then run /dev/buildcache?flush=1, this should create the cache folder and the cached html pages. No need to create this yourself.

    (If you make any template changes you need to run /?flush=1 before /dev/buildcache?flush=1.)

    Oh, and as it says in the documentation the static publisher requires Silverstripe 2.3 .

    Besides the small changes I documented in this thread I just followed the documentation and it worked trouble-free...

    It's a great extension if you don't have much really dynamic content going on.

    Good luck!
    Anatol

  • cliersch
    Avatar
    Community Member
    75 Posts

    Re: Static Publisher - rebuild cache on publishing and home page problem Link to this post

    Hi Anatol,
    Thank you very much for your detailed instructions! Now my staticpublisher works perfectly! )
    Pretty good tool!

  • cliersch
    Avatar
    Community Member
    75 Posts

    Re: Static Publisher - rebuild cache on publishing and home page problem Link to this post

    Ah - I forgot one problem. How do you handle the dynamic sites - the UserDefinedForms like a contact form e.g.
    They don't work or validate staticly - or not?
    Did you write a Rewrite Rule to deliver them dynamicly?
    What is the best way to handle them?

  • bschmitt
    Avatar
    Community Member
    22 Posts

    Re: Static Publisher - rebuild cache on publishing and home page problem Link to this post

    Hi Anatol,

    Tiga's question is interesting for me too. It would be very nice if you can give us a hit, how you manage dynamic content throught the RsyncMultiHostPublisher? Or do you just use the FilesystemPublisher so that you don't have to think about this?

    Many thanks, Bjoern

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