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.

Customising the CMS

Static Publisher - rebuild cache on publishing and home page problem


Go to End
Reply

14 Posts   6004 Views

Avatar
Anatol

6 March 2009 at 2:29pm (Last edited: 6 March 2009 2:35pm), 126 Posts

Hi,

I just enabled the [url=http://doc.silverstripe.com/doku.php?id=staticpublisher]static publisher[/url]. 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 [url=http://doc.silverstripe.com/doku.php?id=staticpublisher#cache_control]php cache control[/url] 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 [url=http://open.silverstripe.com/browser/modules/cms/trunk/code/staticpublisher/htaccess_example_rsyncsingleserver].htaccess file[/url] 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

Avatar
Anatol

9 March 2009 at 3:04pm (Last edited: 9 March 2009 3:04pm), 126 Posts

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 [url=http://doc.silverstripe.com/doku.php?id=staticpublisher#usage]Page.php[/url]) 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 [url=http://open.silverstripe.com/browser/modules/cms/trunk/code/staticpublisher/htaccess_example_rsyncsingleserver].htaccess file[/url] 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

Avatar
Anatol

9 March 2009 at 4:24pm (Last edited: 9 March 2009 4:24pm), 126 Posts

Hi,

one more problem is solved. There is a minor mistake on the [url=http://open.silverstripe.com/browser/modules/cms/trunk/code/staticpublisher/htaccess_example_rsyncsingleserver].htaccess sample file[/url] 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 [url=http://open.silverstripe.com/browser/modules/cms/trunk/code/staticpublisher/htaccess_example_rsyncwithphp].htaccess sample file for the php cache control[/url] has the same mistake, and so does the [url=http://open.silverstripe.com/browser/modules/cms/trunk/code/staticpublisher/htaccess_example_rsyncmultiservers].htaccess sample file for multiple server caching[/url].

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

Cheers!
Anatol

Avatar
cliersch

12 March 2009 at 4:56am (Last edited: 12 March 2009 5:23am), Community Member, 75 Posts

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 [url]http://open.silverstripe.com/browser/modules/cms/trunk/code/staticpublisher/htaccess_example_rsyncsingleserver[/url] 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

Avatar
Anatol

12 March 2009 at 10:04am (Last edited: 12 March 2009 10:07am), 126 Posts

Hi tiga,

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

Just make sure you add [url=http://doc.silverstripe.com/doku.php?id=staticpublisher#usage]this code[/url] 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 [url=http://open.silverstripe.com/browser/modules/cms/trunk/code/staticpublisher/htaccess_example_rsyncsingleserver].htaccess file[/url] , 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, [url=http://silverstripe.org/customising-the-cms/show/255571?start=0#post255788]see my previous post[/url].

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 [url=http://doc.silverstripe.com/doku.php?id=staticpublisher]documentation[/url] and it worked trouble-free...

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

Good luck!
Anatol

Avatar
cliersch

12 March 2009 at 10:08pm (Last edited: 12 March 2009 11:06pm), Community Member, 75 Posts

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

Avatar
cliersch

12 March 2009 at 10:59pm (Last edited: 12 March 2009 11:00pm), Community Member, 75 Posts

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?

Avatar
bschmitt

19 March 2009 at 10:20am Community Member, 22 Posts

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

Go to Top