Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2019-03-16 10:45:03

etc
Developer
Registered: 2010-11-11
Posts: 3,393
Website

Re: etc_cache: cache trying hard to be smart

jakob wrote #317102:

Is there a way of disabling caching globally temporarily, for example via a prefs switch or in debugging* mode?

Good idea, thanks, will think of it.

I’m currently doing flat theme updates to a site and have to clear the cache regularly. Disabling the plugin throws up missing tag errors. You have a $nolog global in the code but I can’t see where it’s actually used.

Well, if your cache update is properly configured, it should be refreshed automatically when something relevant changes, even in debug mode. But I’m not sure that lastmod pref is updated in flat mode, so the cache update is probably not triggered. $nolog serves just to suppress “false” visitors logging when etc_cache “visits” its update page.

*Using debugging mode to disable caching would make things easy, but would one sacrifice being able to debug etc_cache at the same time?

I don’t remember whether etc_cache has its proper debugger. Core-level errors display (syntaxes, etc) shouldn’t be impacted.

Offline

#12 2019-11-14 08:55:54

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,578
Website

Re: etc_cache: cache trying hard to be smart

Hi Oleg,

I’ve come up against a situation where I think I need a special reset / filter combination that I suspect etc_cache is capable of – you’ve made it so wonderfully flexible – but I’m stumped as to how to go about it.

I have a site with annual archives that are perfect for caching as they don’t change once the year is over. The current year, however, changes each week when a new article is published. How would I use reset / filter so that the cache is refreshed whenever an article with a date in the current year is saved? Or – even better – when an article in the same year as the cached block is saved? Also useful would be able to additionally restrict the filter to articles saved in that year in a specific section.


TXP Builders – finely-crafted code, design and txp

Offline

#13 2019-11-14 10:01:48

etc
Developer
Registered: 2010-11-11
Posts: 3,393
Website

Re: etc_cache: cache trying hard to be smart

Hi Julian

jakob wrote #320068:

How would I use reset / filter so that the cache is refreshed whenever an article with a date in the current year is saved?

Do you mean only the cache of the current year? It depends on the parameter used as “year”. Assuming it comes from URL month, you could construct cache blocks like (untested)

<txp:variable name="year" escape="trim">
    <txp:php>
        echo strftime('%Y');
    </txp:php>
</txp:variable>

<txp:evaluate query='<txp:page_url type="month" escape="integer" /> < <txp:variable name="year" />'>
    <txp:etc_cache id='year-<txp:page_url type="month" escape="integer" />' time="10000000000" ... />
<txp:else />
    <txp:etc_cache id='year-<txp:variable name="year" />' time ... />
<txp:evaluate>

Or – even better – when an article in the same year as the cached block is saved?

This looks tricky atm since there is no Year field in textpattern table. Will think of it.

Also useful would be able to additionally restrict the filter to articles saved in that year in a specific section.

You could try to set filter to

{"article_saved":{"Section":"my_section_name"}}

Offline

#14 2019-11-14 10:27:12

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,578
Website

Re: etc_cache: cache trying hard to be smart

etc wrote #320073:

Hi Julian

Do you mean only the cache of the current year? It depends on the parameter used as “year”. Assuming it comes from URL month, you could construct cache blocks like (untested)

<txp:variable name="year" escape="trim">...

My first thought was:

  • when a new article is saved with a posted date of now(ish), the cache for the block for the current year is refreshed. A new article is saved more-or-less once a week.

Then I thought:

  • there might be (infrequent) situations where a past year is edited. One could just simply manually refresh the cache for that year. Or maybe make the reset filter refresh when “the article was posted in the same year as the cached block.

I already have some variables for the respective year / month that I use to name the blocks.

You could try to set filter to

{"article_saved":{"Section":"my_section_name"}}...

You mention in the plugin help that you can use SQL LIKE patterns. Would that mean you could do:

{"article_saved":{"Section":"my_section_name","Posted":"2019%"}}

or something similar. I’m not sure how you chain multiple filter criteria, so the above is just a guess. If one could plug the value of a variable into that Posted bit, I think we would be there…


TXP Builders – finely-crafted code, design and txp

Offline

#15 2019-11-14 10:48:46

etc
Developer
Registered: 2010-11-11
Posts: 3,393
Website

Re: etc_cache: cache trying hard to be smart

jakob wrote #320076:

You mention in the plugin help that you can use SQL LIKE patterns. Would that mean you could do:

{"article_saved":{"Section":"my_section_name","Posted":"2019%"}}...

or something similar. I’m not sure how you chain multiple filter criteria, so the above is just a guess. If one could plug the value of a variable into that Posted bit, I think we would be there…

Not in filter, unfortunately. You can chain multiple criteria as you put above, or even

{"article_saved":{"Section":["my_section_name", "another_section"],"Posted":"2019%"}}

but you need to provide exact values, so 2019% will not work for Posted. And we can not really plug a tag into filter because it is checked on the admin side.

Offline

#16 2019-11-14 14:57:02

etc
Developer
Registered: 2010-11-11
Posts: 3,393
Website

Re: etc_cache: cache trying hard to be smart

Actually, I’m wrong: filter fields are not those of textpattern table but these of article edit form, including year, month and so on. So you can set for each year a filter like

{"article_saved":{"Section":"my_section_name","year":"2019"}}

Here is the (presumably) full list:


    'ID',
    'Title',
    'Body',
    'Excerpt',
    'textile_excerpt',
    'Image',
    'textile_body',
    'Keywords',
    'description',
    'Status',
    'Posted',
    'Expires',
    'Section',
    'Category1',
    'Category2',
    'Annotate',
    'AnnotateInvite',
    'publish_now',
    'reset_time',
    'expire_now',
    'AuthorID',
    'sPosted',
    'LastModID',
    'sLastMod',
    'override_form',
    'from_view',
    'year',
    'month',
    'day',
    'hour',
    'minute',
    'second',
    'url_title',
    'exp_year',
    'exp_month',
    'exp_day',
    'exp_hour',
    'exp_minute',
    'exp_second',
    'sExpires'

Offline

#17 2019-11-16 08:38:52

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,578
Website

Re: etc_cache: cache trying hard to be smart

etc wrote #320088:

Actually, I’m wrong: filter fields are not those of textpattern table but these of article edit form, including year, month and so on. So you can set for each year a filter like

{"article_saved":{"Section":"my_section_name","year":"2019"}}...

Thanks! That’s excellent to know. So, in this case we’re lucky that year, month and day are separate fields in the write pane.

I’m curious: I get why the txp:tag can’t be added to the filter field in the Extensions » etc_cache panel, but if it were possible to pass the filter as an attribute of the tag, like you can with reset, would the tag-in-tag variant work? My thinking was that the tag-as-attribute would be processed first and the results passed to etc_cache.


TXP Builders – finely-crafted code, design and txp

Offline

#18 2019-11-16 09:43:47

etc
Developer
Registered: 2010-11-11
Posts: 3,393
Website

Re: etc_cache: cache trying hard to be smart

jakob wrote #320095:

if it were possible to pass the filter as an attribute of the tag, like you can with reset, would the tag-in-tag variant work? My thinking was that the tag-as-attribute would be processed first and the results passed to etc_cache.

You are right, though JSON is not very practical in txp attributes (nested quotes etc). The main concern with this is what to do when filter changes? Ignore it until cached block expiration? Refresh the block if filter is different from the previous value? Both approaches have their drawbacks.

Offline

Board footer

Powered by FluxBB