Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

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: 4,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: 5,028
Website GitHub

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: 5,028
Website GitHub

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: 4,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: 5,028
Website GitHub

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

#19 2021-02-11 23:11:10

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: etc_cache: cache trying hard to be smart

I’m thinking of enhancing etc_cache with some static site generation abilities. Currently these take a form of a very basic but amazing plugin (independent of etc_cache). FOR TESTING ONLY!

To use it (after install/enable step) you need to append the following to your site .htaccess right after RewriteRule ^(.+) - [PT,L]:

    RewriteCond %{REQUEST_METHOD} =GET
    RewriteCond %{QUERY_STRING} ^$
    RewriteCond %{DOCUMENT_ROOT}/path/to/site/cache/$1 -f [OR]
    RewriteCond %{DOCUMENT_ROOT}/path/to/site/cache/$1index.html -f
    RewriteRule ^(.*) cache/$1 [PT,L]

Replace path/to/site here with the public site path from the document root.

On clean URL access it will create corresponding directories/files under cache directory of your site. On next accesses static files will be served from disk, so txp will not even be launched. When the site is updated, the whole cache directory will be deleted and the caching process will start anew. URLs with ? queries are not cached, so search etc should work ok.

Enjoy!

# Name: etc_static v0.1 
# Type: Admin/Public/AJAX plugin
# Static cache
# Author: Oleg Loukianov
# URL: https://github.com/bloatware/
# Recommended load order: 5

# .....................................................................
# This is a plugin for Textpattern CMS - http://textpattern.com/
# To install: textpattern > admin > plugins
# Paste the following text into the 'Install plugin' box:
# .....................................................................

YToxMTp7czo0OiJuYW1lIjtzOjEwOiJldG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
ZXEnXSwgJy9pbmRleC5waHAnKSA9PT0gMA0KICApIHJldHVybjsNCg0KICBvYl9zdGFydCgp
Ow0KDQogIHJlZ2lzdGVyX2NhbGxiYWNrKGZ1bmN0aW9uKCl7DQogICAgZ2xvYmFsICRwcmV0
ZXh0Ow0KICAgICRjYWNoZSA9ICdjYWNoZS8nOw0KICAgICRkaXIgPSBleHBsb2RlKCcvJywg
bHRyaW0oJHByZXRleHRbJ3JlcSddLCAnLycpKTsNCiAgICBmb3JlYWNoICgkZGlyIGFzICYk
cCkgew0KICAgICAgJHAgPSAkcCAhPT0gJycgPyBzYW5pdGl6ZUZvckZpbGUoJHApIDogJ2lu
ZGV4Lmh0bWwnOw0KICAgIH0NCiAgICANCiAgICB1bnNldCgkcCk7DQogICAgJGZpbGUgPSBh
cnJheV9wb3AoJGRpcik7DQogICAgJGRpciA9ICRjYWNoZS5pbXBsb2RlKCcvJywgJGRpcik7
DQogICAgaWYgKCFpc19kaXIoJGRpcikpIG1rZGlyKCRkaXIsIDA3NzcsIHRydWUpOw0KICAg
ICRvdXQgPSBvYl9nZXRfY2xlYW4oKTsNCiAgICBmaWxlX3B1dF9jb250ZW50cygkZGlyLicv
Jy4kZmlsZSwgJG91dCk7DQogICAgZWNobyAkb3V0Ow0KICB9LCAndGV4dHBhdHRlcm5fZW5k
Jyk7DQp9LCAndGV4dHBhdHRlcm4nKTsNCiI7czo0OiJ0eXBlIjtzOjE6IjUiO3M6NToib3Jk
ZXIiO3M6MToiNSI7czo1OiJmbGFncyI7czoxOiIwIjtzOjQ6ImhlbHAiO3M6MDoiIjtzOjM6
Im1kNSI7czozMjoiYjJmYTMzOTc2MmUwMDA3MGQ1YjM3N2U3MjU0ODM5OWUiO30=

Offline

#20 2021-02-12 06:42:37

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,595
GitHub Twitter

Re: etc_cache: cache trying hard to be smart

I’m loving it! 👍

Tested on a local server (MAMP PC) without any damages. My flat JavaScript resources work fine, too.
Is there a real performance gain with your plugin, Oleg?
May I can use it, today, within an in production website? 😜

Last edited by Pat64 (2021-02-12 06:45:19)


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#21 2021-02-12 06:56:12

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: etc_cache: cache trying hard to be smart

Sounds great, will test later. Can you choose what pages are cached?

Reminds me of rah_cache which showed promise. Maybe some bits in that code which could be of use?

Offline

#22 2021-02-12 07:26:45

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,595
GitHub Twitter

Re: etc_cache: cache trying hard to be smart

@Phil:

Currently, what I observe, all pages are in cache!


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#23 2021-02-12 07:53:55

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: etc_cache: cache trying hard to be smart

Pat64 wrote #328791:

Is there a real performance gain with your plugin, Oleg?

philwareham wrote #328792:

Reminds me of rah_cache which showed promise. Maybe some bits in that code which could be of use?

Great bits in Jukka’s code, will certainly steal something. But the delivery mechanism is not the same: while rah_cache serves cached files via txp (like etc_cache does), etc_static delegates this to apache server. So no php processing is required at all to serve cached files and the performance gain can be important.

Can you choose what pages are cached?

It’s planned, as well as the cache management.

May I can use it, today, within an in production website? 😜

Saw this bold writing? :-) It would be prudent to wait a week or so, please help me testing meanwhile.

Edit: for an average page on my laptop I get 100ms -> 5ms gain.

Offline

#24 2021-02-12 08:02:59

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,595
GitHub Twitter

Re: etc_cache: cache trying hard to be smart

… No. I prefer never to read anything in bold writing.


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

Board footer

Powered by FluxBB