Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2017-03-20 12:31:27

Registered: 2010-11-11
Posts: 2,163

etc_cache: cache trying hard to be smart

When you have thousands of articles, processing the whole list (say, for creating a sitemap) can become time consuming. It is then a good idea (unless you publish an article every minute) to cache the processed result. Naturally, the cached block must be updated when some article is added/deleted. Most caching plugins trigger this update when the corresponding page is visited after the site update. This has, however, two inconveniences:

  • the first visitor has to wait while the expired block is processed and cached again;
  • every site modification, even irrelevant to the cached content, yields the cache update.

That’s what etc_cache is aimed to solve. The basic usage is

<txp:etc_cache id="heavycode">
	<!-- heavy code -->

The code will be processed and cached until the site is updated. On site update, the plugin will ping the url containing this block, triggering the cache refresh. Hence, the cache will always stay up to date, without penalizing site visitors.

You can be more specific with cache reset criteria. Say, if you need a block to be reset only if the article 3 is updated, edit (Extensions tab) the following fields of etc_cache table:

reset: article_saved
filter: {"article_saved":{"ID":3}}

You can also pass reset attribute directly to etc_cache:

<txp:etc_cache id="archive" reset="article_posted,article_saved,articles_deleted,articles_updated">
	<!-- heavy code building an articles archive -->

If needed, one can pass time attribute to etc_cache:

<txp:etc_cache id="dailycode" time="+1 day">
	<!-- daily code -->

A positive (relative) value of time will indicate that the cache (even a fresh one) must be reset on site update. A negative value will not observe site updates. An absolute value like time='<txp:modified format="%F %T" gmt="1" /> +1 month' will mean “cache it if not modified since one month”.

Info and download. Note that etc_cache requires txp 4.6+ to work properly.

etc_[ query | search | pagination | date | tree | cache ]


Board footer

Powered by FluxBB