Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

etc
Developer
Registered: 2010-11-11
Posts: 2,331
Website

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 -->
</txp:etc_cache>

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 -->
</txp:etc_cache>

If needed, one can pass time attribute to etc_cache:

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

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 ]

Offline

#2 2017-06-12 13:10:41

philwareham
Core designer
From: Farnham, Surrey, UK
Registered: 2009-06-11
Posts: 2,807
Website

Re: etc_cache: cache trying hard to be smart

Hi Oleg,

Does this do a similar function to aks_cache? i.e. can it cache a form for a period of time (say, 5 minutes) regardless of whether the site itself is updated.

Usage case: I have a form that fetches some data from an external site – I want that data to be cached in my form for a few minutes rather than have every visitor request that external data.

Offline

#3 2017-06-12 13:14:00

etc
Developer
Registered: 2010-11-11
Posts: 2,331
Website

Re: etc_cache: cache trying hard to be smart

Hi Phil,

yes, a negative value should do it:

<txp:etc_cache id="external" time="-300">
...
</txp:etc_cache>

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

Offline

#4 2017-06-12 13:26:15

philwareham
Core designer
From: Farnham, Surrey, UK
Registered: 2009-06-11
Posts: 2,807
Website

Re: etc_cache: cache trying hard to be smart

Great, thanks. Will test this out (seems to work in my limited testing).

Offline

#5 2017-07-06 11:52:44

philwareham
Core designer
From: Farnham, Surrey, UK
Registered: 2009-06-11
Posts: 2,807
Website

Re: etc_cache: cache trying hard to be smart

Hi Oleg, any chance you can add this to the etc-plugins repo collection so I can add Composer support and make a couple of tweaks to table layouts?

Also, the negative time value (such as time="-300" for 5 minutes in seconds) – can that accept things such as -1 day and -1 week and so on?

Offline

#6 2017-07-06 14:31:26

etc
Developer
Registered: 2010-11-11
Posts: 2,331
Website

Re: etc_cache: cache trying hard to be smart

Hi Phil, I have created an empty repo, will import files later (or please feel free to add what you dim necessary).

Negative literal values should work as soon as strtotime() interprets them correctly, -1 week etc should be ok.


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

Offline

#7 2017-07-07 11:03:19

philwareham
Core designer
From: Farnham, Surrey, UK
Registered: 2009-06-11
Posts: 2,807
Website

Re: etc_cache: cache trying hard to be smart

Hi Oleg,

I can’t commit to the etc_cache repo, have you added me as a collaborator for that one? I’ve got some updates ready to put into it when I get access.

Offline

#8 2017-07-07 21:38:37

etc
Developer
Registered: 2010-11-11
Posts: 2,331
Website

Re: etc_cache: cache trying hard to be smart

Uh.. sorry Phil, I thought you had admin access to the whole etc-plugins repo. You should be owner now, sorry again.


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

Offline

#9 2017-07-22 13:24:06

philwareham
Core designer
From: Farnham, Surrey, UK
Registered: 2009-06-11
Posts: 2,807
Website

Re: etc_cache: cache trying hard to be smart

Latest release of this plugin is now available on GitHub (or via Composer). I’ve updated the admin panel layout a bit plus better documentation.

Offline

Board footer

Powered by FluxBB