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

19 March 2009 at 11:59am

Hi,

sorry guys, I don't know. I didn't have much time to play with the static publisher. So for now I just work with static content. I would quite like to add the comment functionality, but once you post with the static publisher enabled a new comment is not displayed on the page immediately, only after republishing the page (and possible subpages).

I thought ideally a page and sub pages should be republished when a visitor entered a comment, hit the send button and the comment has been written to the database. But I don't know how to start the republish process at that moment without hacking into the core code. If anyone has any idea please let us know.

The other way is probably to exclude some pages from being cached at all. E.g. pages with dynamic content like some widgets. It should be possible to maybe just overwrite the caching functions allPagesToCache() and subPagesToCache() of these pages (replace it with empty functions for certain page types or add a checkbox like 'can be cached' to the CMS and make caching conditional?). So the caching would not even create cached versions of these pages and so the rewrite rule would automatically use the dynamic page.

I would not like to change the .htaccess file and add a rewrite rule for specific pages that should not be cached. It's a solution but not a good one I think.

Well, just ideas, but nothing concrete here. More input on this would be great if anyone has experience with this. I will look into this again when I really need it, but right now I don't have the time.

Cheers!
Anatol

Avatar
Gutur

Community Member, 17 Posts

2 July 2009 at 8:26am

Tiga, can you skype me tomorrow? I'll help figuring out how to hack the rewriterules for forms and other dynamic content. Will edit this for a quick tutorial once we're done :)
Right now I'm just too tired to think anymore...

Avatar
Garrett

Community Member, 245 Posts

23 September 2009 at 8:46am

Hi,

Thanks for the thread on this; it's been very helpful so far in getting this set up. However, I am getting an error when I run http://www.mysiet.com/dev/buildcache?flush=1:

---------------------------------------------

[Warning] mkdir() [function.mkdir]: Invalid argument
GET /dev/buildcache?flush=1

Line 20 in C:\...\sapphire\filesystem\Filesystem.php
Source

11 public static $folder_create_mask = 02775;
12
13 protected static $cache_folderModTime;
14
15 /**
16 * Create a folder, recursively
17 */
18 static function makeFolder($folder) {
19 if(!file_exists($base = dirname($folder))) self::makeFolder($base);
20 if(!file_exists($folder)) mkdir($folder, Filesystem::$folder_create_mask);
21 }
22
23 /**
24 * Remove a directory and all subdirectories and files
25 * @param $contentsOnly If this is true then the contents of the folder will be removed but not the folder itself
26 */

Trace

* mkdir(../cache/https:,1533)
Line 20 of Filesystem.php
* Filesystem::makeFolder(../cache/https:)
Line 19 of Filesystem.php
* Filesystem::makeFolder(../cache/https://publishercenter.looksmart.com)
Line 19 of Filesystem.php

---------------------------------------

Looks like it's trying to make a folder name with an absolute URL in it? Why would the code do this? And how do I fix it?

Thanks,
Garrett

Avatar
Garrett

Community Member, 245 Posts

23 September 2009 at 9:35am

I think I see what it's doing now. The "Redirect" pages-- those with absolute (offsite) URL's are choking the FilesystemPublisher. The code appears to be attempting to name a Folder using a URL. I.e.: something with Slashes and Colons in it. Why would I want to cache pages that don't even live on the site?? This seems like a bug to me.

Anyways, how would I access the ClassName property from /sapphire/Filesystem.php? This way I could check to see if the current object being looked at is a Redirect page and if so, don't cache it. Any better ideas? Help!

Thanks,
Garrett

Avatar
Mohammed

Community Member, 25 Posts

12 January 2010 at 4:10pm

Any luck with getting dynamic content to work while staticpublisher is on? The search function wont work since that's dynamic... :-(

Avatar
Mohammed

Community Member, 25 Posts

12 January 2010 at 6:44pm

Edited: 12/01/2010 6:47pm

Shouldn't I be able to put

Object::add_extension("SiteTree", "RsyncMultiHostPublisher('cache/', 'php')");
in _config.php and
### SILVERSTRIPE START ###
RewriteEngine On

## CONFIG FOR DEV ENVIRONMENTS

# Cached content - **sitedir** subdirectory
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_URI} ^/**sitedir**/(.*)$
RewriteCond %{REQUEST_URI} /**sitedir**/(.*[^/])/?$
RewriteCond %{DOCUMENT_ROOT}/**sitedir**/cache/%1.php -f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /**sitedir**/cache/%1.php [L]

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

## CONFIG FOR TEST/LIVE ENVIRONMENTS

# Cached content - live webserver
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_URI} /(.*[^/])/?$
RewriteCond %{DOCUMENT_ROOT}/cache/%1.php -f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /cache/%1.php [L]

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

## DYNAMIC CONFIG

# Dynamic content
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
### SILVERSTRIPE END ###

in the .htaccess file? This will use the cached php files which are stored in the /cache/ directory AND if it cannot find the php cached version, it will dynamically run whatever page is "missing" when someone opens the page. Enable this will also enable the static (cached) pages to also have HTTP header expirations/the Cache-control features. Am I right?

Go to Top