English فارسی Suomi
Français Nederlands Translate

Campsite 3.4

The Template Cache

To exclude dynamic stuff I've added {{ dynamic }} block. Any code inside dynamic block will be excluded form cache and rendered on each request.

It was first version of template cache handler. It had been working fine but without so many dynamic excluded parts. For given example the cache accelerates just about 2x times than uncached.

That's not fine for me. I'd like more Smile and I've implemented the second template cache handler version with multirendering support. It allows to render included sub-templates by separate rendering process with personal cache settings. The next version contains new function {{ render }}

Full specification:
{{ render file="template_name" [issue=off|issueid] [section=off|sectionid] [article=off|articleid] [params=paremeters] [cache=secs] }}

where

file: template filename
issue: to cache for any issue or for an issue with issueid
section: to cache for any section or for a section with sectionid
article: to cache for any article or for a article with articleid
params: specify additional parameters
cache: overwrite the cache settings in template manager

Let's see on example.
Here is the layout of standard section page.



We need to exclude from caching some dynamic stuff:
1. Most popular list
2. Most commented list
3. External informers
4. Template contains article list pagination.

Let's define some parameters for dynamic stuff:
Most popular article list is defined for issue only.
Most commented article list is defined for all articles in any issue
Informers should be included on each request
Pagination generates links like http://site/en/pub/issue/section/?page=n

Most popular and commented lists should be cached for 600 sec
The main template section.tpl should be cached for 30 days

The cache lifetime for main template can be defined in Template manager:

Most popular list:
{{ render file="most_popular.tpl" section=off cache=600 }}

Most commented list:
{{ render file="most_commented.tpl" issue=off section=off cache=600 }}

Informers:
{{ dynamic }}
{{ php }} inclide 'informer1.php'; {{ php }}
{{ /dynamic }}

Section article list with pagination:
{{ render file="section_list.tpl" params=$campsite->url->get_parameter(page) }}

On article changing or issue publishing/unpublishing the cache manager cleans outdated cached template. Cleaning algorithm based on campsite specific parameters: language, publication, issue, section, article, template, additional params.

 


EDIT