From LifeType Wiki
Contents |
[edit] Page Caching
One of the most interesting features in LifeType 1.0 targetted towards big busy sites is caching. If you expect a lot of traffic to your blog, caching can significantly decrease the amount of time and processor usage your pages will take to load. When enabled, caching will keep a cached copy of each page generated so that next time the same page is requested, it does not need to be generated again.
The caching system allows to save time in two different fronts:
- Since the page is cached and we are sure that the data has not changed, there will be no need to perform any database access. Obviously this has some implications that we will see later on.
- Smarty will not need to spend any time compiling the template because this has already been done.
[edit] How to configure caching
In order to enable caching, template_cache_enabled needs to be enabled (site admin -> template settings) We should also set a value in for template_cache_lifetime, which is the maximum time that cached copies of templates will be considered valid. The value can be:
- -1 in order for pages not to expire. Never.
- 0 in order to disable caching
- anything greater than 0 in order for pages to be considered valid for this many seconds.
Pages in LifeType are also rebuilt whenever data that could potentially change the contents of our pages has changed. For example updating a post will require the whole cache to be cleaned up, including the cache of the summary page (the page with a list of most recent posts in all blogs, most active blogs, etc)
To sum up, pages in LifeType are rebuilt only:
- if data has changed (i.e. a post has been updated, a link has been removed, etc)
- if the lifetime of cached pages expire.
This means that even if we set template_cache_lifetime to -1, pages will still be rebuilt whenever data changes.
[edit] Implications of caching
When caching is enabled, data loading and processing is reduced to a bare minimum in order to serve pages as fast as possible. This has the following implications:
- No data is loaded from the database at all.
- Plugins are loaded but they are not used. So for example plugins that export objects to the templates will not even be initialized. The only plugins that work are filters (see Plugin Development for more information on filters)
- No statistics are counted.
People who enable the caching feature should be aware of this limitations. Of course these are not limitations of a caching system per se but the decisions above were made in order to save as much resources as possible when caching is enabled.
[edit] HTTP Caching
LifeType 1.0 also offers the possibility to serve pages using the response header Last-Modified. This works in collaboration with the request header If-Modified-Since sent by clients.
There is more detailed information available from the W3C but in a nutshell, whenever a page is served with the Last-Modified header, clients will keep this timestamp and the cached version of the page. Next time the same page is requested, the client will inform the server that that page should only be sent if it has been changed since the last time it was fetched. If the page is actually newer, then the server will reply with an HTTP 20x code and send the contents. If the page is older, then the server will reply with an HTTP 302 code and it will not send any page contents. The client will react on this response and will use its cached version.
This will hopefully help to save some bandwidth in busy site whose pages do not change very often.
Needless to say, this feature will not work if template caching is not enabled.
[edit] Resource caching
HTTP caching for resource files (content served via resserver.php) can also be optionally enabled, regardless of whether template caching or HTTP caching for pages is enabled or disabled. It works based on the same principles and it offers the same advantages.
