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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

Static Publisher - rebuild cache on publishing and home page problem


Go to End


14 Posts   9401 Views

Avatar
Anatol

126 Posts

6 March 2009 at 2:29pm

Edited: 06/03/2009 2:35pm

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

Avatar
Anatol

126 Posts

9 March 2009 at 3:04pm

Edited: 09/03/2009 3:04pm

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

Avatar
Anatol

126 Posts

9 March 2009 at 4:24pm

Edited: 09/03/2009 4:24pm

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

Avatar
cliersch

Community Member, 75 Posts

12 March 2009 at 4:56am

Edited: 12/03/2009 5:23am

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

Avatar
Anatol

126 Posts

12 March 2009 at 10:04am

Edited: 12/03/2009 10:07am

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

Avatar
cliersch

Community Member, 75 Posts

12 March 2009 at 10:08pm

Edited: 12/03/2009 11:06pm

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

Avatar
cliersch

Community Member, 75 Posts

12 March 2009 at 10:59pm

Edited: 12/03/2009 11:00pm

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

Community Member, 22 Posts

19 March 2009 at 10:20am

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