Template parser has special <inp2:m_Cache key="..." cache_timeout="..."> ... </inp2:m_Cache/>
tag, that allows developer to cache arbitrary fragments of the page. Tag accepts 2 optional parameters:
- "key" - allows to include/exclude data sources that are monitored to automatically invalidate cached data, when data is monitored source is changed
- "cache_timeout" - value in seconds after which cached data needs to be invalidated regardless of specified in "key" data sources
The value of "key" parameter is list of type/value pairs, where:
- pairs are separated by ";": "type1:value1;type2:value2;..."
- values in the pair (if there are several) are separated by comma: "type1:value1", "type2:value1,value2,..."
Here are list of supported types:
Type | Description |
---|---|
prefix | Unit config prefix. Invalidates cached data, when associated database table content is changed. Cached data only for latest database state is kept. |
prefix_id | Unit config prefix. Invalidates cached data, when currently viewed record (e.g. product on detail page) data in database is changed. Cached data only for latest database state is kept. |
var | Request variable (get/post). Invalidates data, when value for specified request variable changes. Cached data for each possible request variable value is stored in parallel. |
To simplify developer life each cached key will also contain this configuration:
var:m_lang,t,admin,editing_mode,m_cat_id,m_cat_page,page,per_page,sort_by;prefix:theme-file,phrases,conf
If a need arises to exclude any of built-in types, then it can be done by prepending "skip_" before above mentioned types. For example to exclude "var:admin" specify "skip_var:admin" in the key.
Proposing to add "param" type (and "skip_param" type), that will allow using current template variables to form cache key. That for example will allow to cache contents of template blocks, that are called from different places with different parameters.
Solution
In the "\NParser::FormCacheKey" method:
- "param" and "skip_param" types (see how "var" and "skip_var" are implemented), that would use "$this->GetParam" to get parameter value
- prefix cache key parts, that are added to $parts array based on their type to avoid conflicts (e.g. when template parameter is named like request variable)