mirror of
https://github.com/silverstripe/silverstripe-staticpublisher
synced 2024-10-22 14:05:54 +02:00
FIX Docs formatting and errors
Fixed some formatting and documentation errors
This commit is contained in:
parent
bd19b2cc75
commit
9a880dc066
@ -19,6 +19,6 @@ static files to both a local or remote server for increased site performance.
|
|||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
See the docs folder.
|
See the [docs](docs/) folder.
|
||||||
|
|
||||||
Note this is untested on Windows.
|
Note this is untested on Windows.
|
@ -10,101 +10,103 @@ Static Publishing will generate static versions of your content (HTML, XML)
|
|||||||
whenever you publish a web page in the CMS and allow you to publish the page
|
whenever you publish a web page in the CMS and allow you to publish the page
|
||||||
as HTML.
|
as HTML.
|
||||||
|
|
||||||
See `[StaticExporter]` for a less flexible, but easier way of building a
|
See [`StaticExporter`](StaticExporter.md) for a less flexible, but easier way of
|
||||||
local static cache from all of your pages.
|
building a local static cache from all of your pages.
|
||||||
|
|
||||||
See [Partial-Caching](partial-caching) for a much more flexible way of building
|
See [`Partial-Caching`](http://doc.silverstripe.org/framework/en/reference/partial-caching)
|
||||||
in caching without delivering static content. Partial Caching is recommended as
|
for a much more flexible way of building in caching without delivering static
|
||||||
a basic enhancement to any SilverStripe site however if your site is planning a
|
content. Partial Caching is recommended as a basic enhancement to any SilverStripe
|
||||||
vast amount of traffic (eg an article is being dug) then Static Publisher will
|
site however if your site is planning a vast amount of traffic (eg an article is
|
||||||
be appropriate.
|
being dug) then Static Publisher will be appropriate.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
SilverStripe doesn't have enough information about your template and data
|
SilverStripe doesn't have enough information about your template and data
|
||||||
structures to automatically determine which URLs need to be cached, and at
|
structures to automatically determine which URLs need to be cached, and at
|
||||||
which time they are considered outdated. By adding a custom method
|
which time they are considered outdated. By adding a custom method
|
||||||
`allPagesToCache() to your Page class, you can determine which URLs need
|
`allPagesToCache()` to your Page class, you can determine which URLs need
|
||||||
caching, and hook in custom logic. This array of URLs is used by the publisher
|
caching, and hook in custom logic. This array of URLs is used by the publisher
|
||||||
to generate folders and HTML-files.
|
to generate folders and HTML-files.
|
||||||
|
|
||||||
First add the FilesystemPublisher extension to your object. See the
|
First add the `FilesystemPublisher` extension to your object. See the
|
||||||
[DataExtension](http://doc.silverstripe.org/framework/en/reference/dataextension)
|
[DataExtension](http://doc.silverstripe.org/framework/en/reference/dataextension)
|
||||||
documentation for more ways to add the extension to your SiteTree.
|
documentation for more ways to add the extension to your `SiteTree`.
|
||||||
|
|
||||||
:::php
|
```php
|
||||||
SiteTree::add_extension("FilesystemPublisher('cache/')");
|
SiteTree::add_extension("FilesystemPublisher('cache/')");
|
||||||
|
```
|
||||||
|
|
||||||
Once you've added the extension, define the pages you would like to cache from
|
Once you've added the extension, define the pages you would like to cache from
|
||||||
your Page class:
|
your `Page` class:
|
||||||
|
|
||||||
:::php
|
```php
|
||||||
class Page extends SiteTree {
|
class Page extends SiteTree {
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a list of all the pages to cache
|
* Return a list of all the pages to cache
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function allPagesToCache() {
|
public function allPagesToCache() {
|
||||||
// Get each page type to define its sub-urls
|
// Get each page type to define its sub-urls
|
||||||
$urls = array();
|
$urls = array();
|
||||||
|
|
||||||
// memory intensive depending on number of pages
|
// memory intensive depending on number of pages
|
||||||
$pages = Page::get();
|
$pages = Page::get();
|
||||||
|
|
||||||
foreach($pages as $page) {
|
foreach($pages as $page) {
|
||||||
$urls = array_merge($urls, (array)$page->subPagesToCache());
|
$urls = array_merge($urls, (array)$page->subPagesToCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
// add any custom URLs which are not SiteTree instances
|
|
||||||
$urls[] = "sitemap.xml";
|
|
||||||
|
|
||||||
return $urls;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of URLs to cache related to this page.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function subPagesToCache() {
|
|
||||||
$urls = array();
|
|
||||||
|
|
||||||
// add current page
|
|
||||||
$urls[] = $this->Link();
|
|
||||||
|
|
||||||
// cache the RSS feed if comments are enabled
|
|
||||||
if ($this->ProvideComments) {
|
|
||||||
$urls[] = Director::absoluteBaseURL() . "CommentingController/rss/SiteTree/" . $this->ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $urls;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of URL's to publish when this page changes
|
|
||||||
*/
|
|
||||||
public function pagesAffectedByChanges() {
|
|
||||||
$urls = $this->subPagesToCache();
|
|
||||||
if($p = $this->Parent) $urls = array_merge((array)$urls, (array)$p->subPagesToCache());
|
|
||||||
return $urls;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// add any custom URLs which are not SiteTree instances
|
||||||
|
$urls[] = "sitemap.xml";
|
||||||
|
|
||||||
|
return $urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of URLs to cache related to this page.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function subPagesToCache() {
|
||||||
|
$urls = array();
|
||||||
|
|
||||||
|
// add current page
|
||||||
|
$urls[] = $this->Link();
|
||||||
|
|
||||||
|
// cache the RSS feed if comments are enabled
|
||||||
|
if ($this->ProvideComments) {
|
||||||
|
$urls[] = Director::absoluteBaseURL() . "CommentingController/rss/SiteTree/" . $this->ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $urls;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of URL's to publish when this page changes
|
||||||
|
*/
|
||||||
|
public function pagesAffectedByChanges() {
|
||||||
|
$urls = $this->subPagesToCache();
|
||||||
|
if($p = $this->Parent) $urls = array_merge((array)$urls, (array)$p->subPagesToCache());
|
||||||
|
return $urls;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Excluding Pages
|
## Excluding Pages
|
||||||
|
|
||||||
The allPagesToCache function returns all the URLs needed to cache. So if you
|
The `allPagesToCache` function returns all the URLs needed to cache. So if you
|
||||||
want to exclude specific pages from the cache then you unset these URLs from
|
want to exclude specific pages from the cache then you unset these URLs from
|
||||||
the returned array. If you do not want to cache a specific class (eg
|
the returned array. If you do not want to cache a specific class (eg
|
||||||
UserDefinedForms) you can also add an exclusion
|
`UserDefinedForms`) you can also add an exclusion
|
||||||
|
|
||||||
:::php
|
```php
|
||||||
class Page extends SiteTree {
|
class Page extends SiteTree {
|
||||||
// ..
|
// ..
|
||||||
|
|
||||||
public function allPagesToCache() {
|
public function allPagesToCache() {
|
||||||
$urls = array();
|
$urls = array();
|
||||||
@ -122,14 +124,18 @@ UserDefinedForms) you can also add an exclusion
|
|||||||
|
|
||||||
return $urls;
|
return $urls;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
You can also pass the filtering to the original `SiteTree::get()`;
|
You can also pass the filtering to the original `SiteTree::get()`;
|
||||||
|
|
||||||
:::php
|
```php
|
||||||
public function allPagesToCache() {
|
public function allPagesToCache() {
|
||||||
$urls = array();
|
$urls = array();
|
||||||
$pages = SiteTree::get()->where("ClassName != 'UserDefinedForm'");
|
$pages = SiteTree::get()->where("ClassName != 'UserDefinedForm'");
|
||||||
...
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Single server Caching
|
## Single server Caching
|
||||||
|
|
||||||
@ -138,142 +144,149 @@ is good for a basic performance enhancement.
|
|||||||
|
|
||||||
### Setup
|
### Setup
|
||||||
|
|
||||||
Put this in mysite/_config.php. This will create static content in a
|
Put this in `mysite/_config.php`. This will create static content in a
|
||||||
"cache/" subdirectory, with an HTML suffix.
|
"cache/" subdirectory, with an HTML suffix.
|
||||||
|
|
||||||
:::php
|
```php
|
||||||
Object::add_extension("SiteTree", "FilesystemPublisher('cache/', 'html')");
|
Object::add_extension("SiteTree", "FilesystemPublisher('cache/', 'html')");
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
* Put this into your .htaccess. It will serve requests from the cache,
|
* Put this into your `.htaccess`. It will serve requests from the cache,
|
||||||
statically, if the cache file exists. Replace **sitedir** with the a sub
|
statically, if the cache file exists. Replace **sitedir** with the a sub
|
||||||
directory that you would like to serve the site from (for example, in
|
directory that you would like to serve the site from (for example, in
|
||||||
your dev environment).
|
your dev environment).
|
||||||
|
|
||||||
RewriteEngine On
|
```
|
||||||
|
RewriteEngine On
|
||||||
|
|
||||||
## CONFIG FOR DEV ENVIRONMENTS
|
## CONFIG FOR DEV ENVIRONMENTS
|
||||||
|
|
||||||
# Cached content - **sitedir** subdirectory
|
# Cached content - **sitedir** subdirectory
|
||||||
RewriteCond %{REQUEST_METHOD} ^GET$
|
RewriteCond %{REQUEST_METHOD} ^GET$
|
||||||
RewriteCond %{QUERY_STRING} ^$
|
RewriteCond %{QUERY_STRING} ^$
|
||||||
RewriteCond %{REQUEST_URI} ^/**sitedir**/(.*)$
|
RewriteCond %{REQUEST_URI} ^/**sitedir**/(.*)$
|
||||||
RewriteCond %{REQUEST_URI} /**sitedir**/(.*[^/])/?$
|
RewriteCond %{REQUEST_URI} /**sitedir**/(.*[^/])/?$
|
||||||
RewriteCond %{DOCUMENT_ROOT}/**sitedir**/cache/%1.html -f
|
RewriteCond %{DOCUMENT_ROOT}/**sitedir**/cache/%1.html -f
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteRule .* /**sitedir**/cache/%1.html [L]
|
RewriteRule .* /**sitedir**/cache/%1.html [L]
|
||||||
|
|
||||||
# Cached content - homepage
|
# Cached content - homepage
|
||||||
RewriteCond %{REQUEST_METHOD} ^GET$
|
RewriteCond %{REQUEST_METHOD} ^GET$
|
||||||
RewriteCond %{QUERY_STRING} ^$
|
RewriteCond %{QUERY_STRING} ^$
|
||||||
RewriteCond %{REQUEST_URI} ^/**sitedir**/?$
|
RewriteCond %{REQUEST_URI} ^/**sitedir**/?$
|
||||||
RewriteCond /**sitedir**/cache/index.html -f
|
RewriteCond /**sitedir**/cache/index.html -f
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteRule .* /**sitedir**/cache/index.html [L]
|
RewriteRule .* /**sitedir**/cache/index.html [L]
|
||||||
|
|
||||||
## CONFIG FOR TEST/LIVE ENVIRONMENTS
|
## CONFIG FOR TEST/LIVE ENVIRONMENTS
|
||||||
|
|
||||||
# Cached content - live webserver
|
# Cached content - live webserver
|
||||||
RewriteCond %{REQUEST_METHOD} ^GET$
|
RewriteCond %{REQUEST_METHOD} ^GET$
|
||||||
RewriteCond %{QUERY_STRING} ^$
|
RewriteCond %{QUERY_STRING} ^$
|
||||||
RewriteCond %{REQUEST_URI} /(.*[^/])/?$
|
RewriteCond %{REQUEST_URI} /(.*[^/])/?$
|
||||||
RewriteCond %{DOCUMENT_ROOT}/cache/%1.html -f
|
RewriteCond %{DOCUMENT_ROOT}/cache/%1.html -f
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteRule .* /cache/%1.html [L]
|
RewriteRule .* /cache/%1.html [L]
|
||||||
|
|
||||||
# Cached content - homepage
|
# Cached content - homepage
|
||||||
RewriteCond %{REQUEST_METHOD} ^GET$
|
RewriteCond %{REQUEST_METHOD} ^GET$
|
||||||
RewriteCond %{QUERY_STRING} ^$
|
RewriteCond %{QUERY_STRING} ^$
|
||||||
RewriteCond %{REQUEST_URI} ^/?$
|
RewriteCond %{REQUEST_URI} ^/?$
|
||||||
RewriteCond %{DOCUMENT_ROOT}/cache/index.html -f
|
RewriteCond %{DOCUMENT_ROOT}/cache/index.html -f
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteRule .* /cache/index.html [L]
|
RewriteRule .* /cache/index.html [L]
|
||||||
|
|
||||||
## DYNAMIC CONFIG
|
## DYNAMIC CONFIG
|
||||||
|
|
||||||
# Dynamic content
|
# Dynamic content
|
||||||
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
|
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
|
||||||
RewriteCond %{REQUEST_URI} ^(.*)$
|
RewriteCond %{REQUEST_URI} ^(.*)$
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteRule .* staticpublisher/code/main.php?url=%1&%{QUERY_STRING} [L]
|
RewriteRule .* staticpublisher/main.php?url=%1&%{QUERY_STRING} [L]
|
||||||
### SILVERSTRIPE END ###
|
### SILVERSTRIPE END ###
|
||||||
|
```
|
||||||
|
|
||||||
|
* We use a simple PHP script, `static-main.php`, to control cache lookup. This
|
||||||
* We use a simple PHP script, static-main.php, to control cache lookup. This
|
makes the `.htaccess` update simpler.
|
||||||
makes the .htaccess update simpler.
|
|
||||||
|
|
||||||
Just look for this line:
|
Just look for this line:
|
||||||
|
|
||||||
RewriteRule .* framework/main.php?url=%1&%{QUERY_STRING} [L]
|
```
|
||||||
|
RewriteRule .* framework/main.php?url=%1&%{QUERY_STRING} [L]
|
||||||
|
```
|
||||||
|
|
||||||
And change the PHP script from main.php to static-main.php:
|
And change the PHP script from `main.php` to `static-main.php`:
|
||||||
|
|
||||||
RewriteRule .* staticpublisher/code/main.php?url=%1&%{QUERY_STRING} [L]
|
```
|
||||||
|
RewriteRule .* staticpublisher/main.php?url=%1&%{QUERY_STRING} [L]
|
||||||
|
```
|
||||||
|
|
||||||
## Using Static Publisher With Subsites Module
|
## Using Static Publisher With Subsites Module
|
||||||
|
|
||||||
Append the following code to mysite/config.php
|
Append the following code to mysite/config.php
|
||||||
|
|
||||||
:::php
|
```php
|
||||||
FilesystemPublisher::$domain_based_caching = true;
|
FilesystemPublisher::$domain_based_caching = true;
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
Instead of the above code snippet for Page.php, use the following code:
|
Instead of the above code snippet for `Page.php`, use the following code:
|
||||||
|
|
||||||
:::php
|
```php
|
||||||
class Page extends SiteTree {
|
class Page extends SiteTree {
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
public function allPagesToCache() {
|
public function allPagesToCache() {
|
||||||
// Get each page type to define its sub-urls
|
// Get each page type to define its sub-urls
|
||||||
$urls = array();
|
$urls = array();
|
||||||
|
|
||||||
// memory intensive depending on number of pages
|
// memory intensive depending on number of pages
|
||||||
$pages = Subsite::get_from_all_subsites("SiteTree");
|
$pages = Subsite::get_from_all_subsites("SiteTree");
|
||||||
|
|
||||||
foreach($pages as $page) {
|
foreach($pages as $page) {
|
||||||
$urls = array_merge($urls, (array)$page->subPagesToCache());
|
$urls = array_merge($urls, (array)$page->subPagesToCache());
|
||||||
}
|
|
||||||
|
|
||||||
return $urls;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function subPagesToCache() {
|
return $urls;
|
||||||
$urls = array();
|
|
||||||
$urls[] = $this->AbsoluteLink();
|
|
||||||
return $urls;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function pagesAffectedByChanges() {
|
|
||||||
$urls = $this->subPagesToCache();
|
|
||||||
if($p = $this->Parent) $urls = array_merge((array)$urls, (array)$p->subPagesToCache());
|
|
||||||
return $urls;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ... some other code ...
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function subPagesToCache() {
|
||||||
|
$urls = array();
|
||||||
|
$urls[] = $this->AbsoluteLink();
|
||||||
|
return $urls;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function pagesAffectedByChanges() {
|
||||||
|
$urls = $this->subPagesToCache();
|
||||||
|
if($p = $this->Parent) $urls = array_merge((array)$urls, (array)$p->subPagesToCache());
|
||||||
|
return $urls;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ... some other code ...
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
And the last thing you need to do is adding your main site's host mapping to
|
And the last thing you need to do is adding your main site's host mapping to
|
||||||
subsites/host-map.php. For example, your main site's host is mysite.com the
|
`subsites/host-map.php`. For example, your main site's host is mysite.com the
|
||||||
content of the file would be:
|
content of the file would be:
|
||||||
|
|
||||||
:::php
|
```php
|
||||||
<?php
|
<?php
|
||||||
$subsiteHostmap = array (
|
$subsiteHostmap = array (
|
||||||
// .. subsite hots mapping ..,
|
// .. subsite hots mapping ..,
|
||||||
'mysite.com', 'mysite.com'
|
'mysite.com', 'mysite.com'
|
||||||
);
|
);
|
||||||
|
```
|
||||||
|
|
||||||
Remember that you need to add main site's host mapping every time a subsite is
|
Remember that you need to add main site's host mapping every time a subsite is
|
||||||
added or modified because the operation overwrites your manual modification
|
added or modified because the operation overwrites your manual modification
|
||||||
to the file and subsite module does not add main site's hot mapping automatically
|
to the file and subsite module does not add main site's hot mapping automatically
|
||||||
at the moment.
|
at the moment.
|
||||||
|
|
||||||
Another note for host-map.php file. This file doesn't not exist until you have
|
Another note for `host-map.php` file. This file doesn't not exist until you have
|
||||||
created at least one subsite.
|
created at least one subsite.
|
||||||
|
|
||||||
## Multiple Server Caching
|
## Multiple Server Caching
|
||||||
@ -292,17 +305,17 @@ also good for high-traffic situations.
|
|||||||
|
|
||||||
### Setup
|
### Setup
|
||||||
|
|
||||||
Add the RsyncMultiHostPublisher extension to your SiteTree objects in
|
Add the `RsyncMultiHostPublisher` extension to your `SiteTree` objects in
|
||||||
`mysite/_config.php`. This will create static content in a "cache/" sub
|
`mysite/_config.php`. This will create static content in a "cache/" sub
|
||||||
directory, with an HTML suffix.
|
directory, with an HTML suffix.
|
||||||
|
|
||||||
:::php
|
```php
|
||||||
Object::add_extension("SiteTree", "RsyncMultiHostPublisher('cache/', 'html')");
|
Object::add_extension("SiteTree", "RsyncMultiHostPublisher('cache/', 'html')");
|
||||||
RsyncMultiHostPublisher::set_targets(array(
|
RsyncMultiHostPublisher::set_targets(array(
|
||||||
'<rsyncuser>@<static-server1>:<webroot>',
|
'<rsyncuser>@<static-server1>:<webroot>',
|
||||||
'<rsyncuser>@<static-server2>:<webroot>',
|
'<rsyncuser>@<static-server2>:<webroot>',
|
||||||
));
|
));
|
||||||
|
```
|
||||||
|
|
||||||
Where `<rsyncuser>` is a unix account with write permissions to `<webroot>`
|
Where `<rsyncuser>` is a unix account with write permissions to `<webroot>`
|
||||||
(e.g. `/var/www`), and `<static-server1>` and `<static-server2>` are the names
|
(e.g. `/var/www`), and `<static-server1>` and `<static-server2>` are the names
|
||||||
@ -317,51 +330,53 @@ key-based authentication without requiring a password for the username
|
|||||||
specified in `<rsyncuser>` (see [http://www.csua.berkeley.edu/~ranga/notes/ssh_nopass.html
|
specified in `<rsyncuser>` (see [http://www.csua.berkeley.edu/~ranga/notes/ssh_nopass.html
|
||||||
tutorial](http://www.csua.berkeley.edu/~ranga/notes/ssh_nopass.html tutorial)).
|
tutorial](http://www.csua.berkeley.edu/~ranga/notes/ssh_nopass.html tutorial)).
|
||||||
|
|
||||||
* Put the .htaccess file linked below into the webroot of each static content
|
* Put the `.htaccess` file linked below into the webroot of each static content
|
||||||
server (and rename it to `.htaccess`). It will serve requests from the cache,
|
server (and rename it to `.htaccess`). It will serve requests from the cache,
|
||||||
statically, if the cache file exists. Replace **sitedir** with the a
|
statically, if the cache file exists. Replace **sitedir** with the a
|
||||||
subdirectory that you would like to serve the site from (for example, in your
|
subdirectory that you would like to serve the site from (for example, in your
|
||||||
dev environment).
|
dev environment).
|
||||||
|
|
||||||
### SILVERSTRIPE START ###
|
```
|
||||||
RewriteEngine On
|
### SILVERSTRIPE START ###
|
||||||
|
RewriteEngine On
|
||||||
|
|
||||||
## CONFIG FOR DEV ENVIRONMENTS
|
## CONFIG FOR DEV ENVIRONMENTS
|
||||||
|
|
||||||
# Cached content - **sitedir** subdirectory
|
# Cached content - **sitedir** subdirectory
|
||||||
RewriteCond %{REQUEST_METHOD} ^GET$
|
RewriteCond %{REQUEST_METHOD} ^GET$
|
||||||
RewriteCond %{QUERY_STRING} ^$
|
RewriteCond %{QUERY_STRING} ^$
|
||||||
RewriteCond %{REQUEST_URI} ^/**sitedir**/(.*)$
|
RewriteCond %{REQUEST_URI} ^/**sitedir**/(.*)$
|
||||||
RewriteCond %{REQUEST_URI} /**sitedir**/(.*[^/])/?$
|
RewriteCond %{REQUEST_URI} /**sitedir**/(.*[^/])/?$
|
||||||
RewriteCond %{DOCUMENT_ROOT}/**sitedir**/cache/%1.html -f
|
RewriteCond %{DOCUMENT_ROOT}/**sitedir**/cache/%1.html -f
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteRule .* /**sitedir**/cache/%1.html [L]
|
RewriteRule .* /**sitedir**/cache/%1.html [L]
|
||||||
|
|
||||||
# Cached content - homepage
|
# Cached content - homepage
|
||||||
RewriteCond %{REQUEST_METHOD} ^GET$
|
RewriteCond %{REQUEST_METHOD} ^GET$
|
||||||
RewriteCond %{QUERY_STRING} ^$
|
RewriteCond %{QUERY_STRING} ^$
|
||||||
RewriteCond %{REQUEST_URI} ^/**sitedir**/?$
|
RewriteCond %{REQUEST_URI} ^/**sitedir**/?$
|
||||||
RewriteCond /**sitedir**/cache/index.html -f
|
RewriteCond /**sitedir**/cache/index.html -f
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteRule .* /**sitedir**/cache/index.html [L]
|
RewriteRule .* /**sitedir**/cache/index.html [L]
|
||||||
|
|
||||||
## CONFIG FOR TEST/LIVE ENVIRONMENTS
|
## CONFIG FOR TEST/LIVE ENVIRONMENTS
|
||||||
|
|
||||||
# Cached content - live webserver
|
# Cached content - live webserver
|
||||||
RewriteCond %{REQUEST_METHOD} ^GET$
|
RewriteCond %{REQUEST_METHOD} ^GET$
|
||||||
RewriteCond %{QUERY_STRING} ^$
|
RewriteCond %{QUERY_STRING} ^$
|
||||||
RewriteCond %{REQUEST_URI} /(.*[^/])/?$
|
RewriteCond %{REQUEST_URI} /(.*[^/])/?$
|
||||||
RewriteCond %{DOCUMENT_ROOT}/cache/%1.html -f
|
RewriteCond %{DOCUMENT_ROOT}/cache/%1.html -f
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteRule .* /cache/%1.html [L]
|
RewriteRule .* /cache/%1.html [L]
|
||||||
|
|
||||||
# Cached content - homepage
|
# Cached content - homepage
|
||||||
RewriteCond %{REQUEST_METHOD} ^GET$
|
RewriteCond %{REQUEST_METHOD} ^GET$
|
||||||
RewriteCond %{QUERY_STRING} ^$
|
RewriteCond %{QUERY_STRING} ^$
|
||||||
RewriteCond %{REQUEST_URI} ^/?$
|
RewriteCond %{REQUEST_URI} ^/?$
|
||||||
RewriteCond %{DOCUMENT_ROOT}/cache/index.html -f
|
RewriteCond %{DOCUMENT_ROOT}/cache/index.html -f
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteRule .* /cache/index.html [L]
|
RewriteRule .* /cache/index.html [L]
|
||||||
|
```
|
||||||
|
|
||||||
## Cache Control
|
## Cache Control
|
||||||
|
|
||||||
@ -374,54 +389,57 @@ last modification date for each static file is controlled by the publication
|
|||||||
script, meaning the cache gets invalidated on each publication.
|
script, meaning the cache gets invalidated on each publication.
|
||||||
|
|
||||||
To enable cache control, specify "php" instead of "html" in the
|
To enable cache control, specify "php" instead of "html" in the
|
||||||
RsyncMultiHostPublisher definition.
|
`RsyncMultiHostPublisher` definition.
|
||||||
|
|
||||||
:::php
|
```
|
||||||
Object::add_extension("SiteTree", "RsyncMultiHostPublisher('cache/', 'php')");
|
Object::add_extension("SiteTree", "RsyncMultiHostPublisher('cache/', 'php')");
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
And use this slightly different .htaccess file. Make sure that index.php can be
|
And use this slightly different `.htaccess` file. Make sure that `index.php` can
|
||||||
used as a directory index in your apache (`DirectoryIndex`) or nginx (`index`)
|
be used as a directory index in your apache (`DirectoryIndex`) or nginx (`index`)
|
||||||
|
|
||||||
### SILVERSTRIPE START ###
|
```
|
||||||
RewriteEngine On
|
### SILVERSTRIPE START ###
|
||||||
|
RewriteEngine On
|
||||||
|
|
||||||
## CONFIG FOR DEV ENVIRONMENTS
|
## CONFIG FOR DEV ENVIRONMENTS
|
||||||
|
|
||||||
# Cached content - **sitedir** subdirectory
|
# Cached content - **sitedir** subdirectory
|
||||||
RewriteCond %{REQUEST_METHOD} ^GET$
|
RewriteCond %{REQUEST_METHOD} ^GET$
|
||||||
RewriteCond %{QUERY_STRING} ^$
|
RewriteCond %{QUERY_STRING} ^$
|
||||||
RewriteCond %{REQUEST_URI} ^/**sitedir**/(.*)$
|
RewriteCond %{REQUEST_URI} ^/**sitedir**/(.*)$
|
||||||
RewriteCond %{REQUEST_URI} /**sitedir**/(.*[^/])/?$
|
RewriteCond %{REQUEST_URI} /**sitedir**/(.*[^/])/?$
|
||||||
RewriteCond %{DOCUMENT_ROOT}/**sitedir**/cache/%1.php -f
|
RewriteCond %{DOCUMENT_ROOT}/**sitedir**/cache/%1.php -f
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteRule .* /**sitedir**/cache/%1.php [L]
|
RewriteRule .* /**sitedir**/cache/%1.php [L]
|
||||||
|
|
||||||
# Cached content - homepage
|
# Cached content - homepage
|
||||||
RewriteCond %{REQUEST_METHOD} ^GET$
|
RewriteCond %{REQUEST_METHOD} ^GET$
|
||||||
RewriteCond %{QUERY_STRING} ^$
|
RewriteCond %{QUERY_STRING} ^$
|
||||||
RewriteCond %{REQUEST_URI} ^/**sitedir**/?$
|
RewriteCond %{REQUEST_URI} ^/**sitedir**/?$
|
||||||
RewriteCond /**sitedir**/cache/index.php -f
|
RewriteCond /**sitedir**/cache/index.php -f
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteRule .* /**sitedir**/cache/index.php [L]
|
RewriteRule .* /**sitedir**/cache/index.php [L]
|
||||||
|
|
||||||
## CONFIG FOR TEST/LIVE ENVIRONMENTS
|
## CONFIG FOR TEST/LIVE ENVIRONMENTS
|
||||||
|
|
||||||
# Cached content - live webserver
|
# Cached content - live webserver
|
||||||
RewriteCond %{REQUEST_METHOD} ^GET$
|
RewriteCond %{REQUEST_METHOD} ^GET$
|
||||||
RewriteCond %{QUERY_STRING} ^$
|
RewriteCond %{QUERY_STRING} ^$
|
||||||
RewriteCond %{REQUEST_URI} /(.*[^/])/?$
|
RewriteCond %{REQUEST_URI} /(.*[^/])/?$
|
||||||
RewriteCond %{DOCUMENT_ROOT}/cache/%1.php -f
|
RewriteCond %{DOCUMENT_ROOT}/cache/%1.php -f
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteRule .* /cache/%1.php [L]
|
RewriteRule .* /cache/%1.php [L]
|
||||||
|
|
||||||
# Cached content - homepage
|
# Cached content - homepage
|
||||||
RewriteCond %{REQUEST_METHOD} ^GET$
|
RewriteCond %{REQUEST_METHOD} ^GET$
|
||||||
RewriteCond %{QUERY_STRING} ^$
|
RewriteCond %{QUERY_STRING} ^$
|
||||||
RewriteCond %{REQUEST_URI} ^/?$
|
RewriteCond %{REQUEST_URI} ^/?$
|
||||||
RewriteCond %{DOCUMENT_ROOT}/cache/index.php -f
|
RewriteCond %{DOCUMENT_ROOT}/cache/index.php -f
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteRule .* /cache/index.php [L]
|
RewriteRule .* /cache/index.php [L]
|
||||||
|
```
|
||||||
|
|
||||||
## Deployment
|
## Deployment
|
||||||
|
|
||||||
@ -430,20 +448,23 @@ you can build the static HTML files. This is done by the `RebuildStaticCacheTask
|
|||||||
|
|
||||||
Execution via URL
|
Execution via URL
|
||||||
|
|
||||||
http://www.yoursite.com/dev/buildcache?flush=1
|
```
|
||||||
|
http://www.yoursite.com/dev/buildcache?flush=1
|
||||||
|
```
|
||||||
|
|
||||||
Execution on CLI (via [sake](framework/en/topics/commandline))
|
Execution on CLI (via [sake](framework/en/topics/commandline))
|
||||||
|
```
|
||||||
|
sake dev/buildcache flush=1
|
||||||
|
```
|
||||||
|
|
||||||
sake dev/buildcache flush=1
|
Depending on which extension you've set up for your `SiteTree` (`FilesystemPublisher`
|
||||||
|
or `RsyncMultiHostPublisher`), the method `publishPages()` either stores the generated
|
||||||
Depending on which extension you've set up for your SiteTree (FilesystemPublisher
|
|
||||||
or RsyncMultiHostPublisher), the method publishPages() either stores the generated
|
|
||||||
HTML-files on the server's filesystem, or deploys them to other servers via rsync.
|
HTML-files on the server's filesystem, or deploys them to other servers via rsync.
|
||||||
|
|
||||||
It is advisable to set dev/buildcache up as an automated task (e.g. unix cron)
|
It is advisable to set `dev/buildcache` up as an automated task (e.g. unix cron)
|
||||||
which continually rebuilds and redeploys the cache.
|
which continually rebuilds and redeploys the cache.
|
||||||
|
|
||||||
## Related
|
## Related
|
||||||
|
|
||||||
* `[StaticExporter](StaticExporter)`
|
* [StaticExporter](StaticExporter.md)
|
||||||
* [Partial-Caching](/framework/partial-caching)
|
* [Partial-Caching](http://doc.silverstripe.org/framework/en/reference/partial-caching)
|
||||||
|
@ -13,7 +13,7 @@ increase on those pages. You can run the static content alongside a full
|
|||||||
installation to allow for seamless integration. Also supports syncing published
|
installation to allow for seamless integration. Also supports syncing published
|
||||||
content to multiple servers for load balancing.
|
content to multiple servers for load balancing.
|
||||||
|
|
||||||
* [Static Publisher](StaticPublisher)
|
* [Static Publisher](StaticPublisher.md)
|
||||||
|
|
||||||
## Static Exporter
|
## Static Exporter
|
||||||
|
|
||||||
@ -21,4 +21,4 @@ Export your entire website to HTML pages. Suitable if your entire site is
|
|||||||
static and you wish to deploy the content to a machine other than the CMS or
|
static and you wish to deploy the content to a machine other than the CMS or
|
||||||
as a backup measure to your website
|
as a backup measure to your website
|
||||||
|
|
||||||
* [Static Exporter](StaticExporter)
|
* [Static Exporter](StaticExporter.md)
|
||||||
|
Loading…
Reference in New Issue
Block a user