Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2004-08-07 04:18:09
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
[plugin] [ORPHAN] zem_cache: experiment
A number of people have been asking about a ‘staticize’ clone for Textpattern. I’m not yet convinced that such a thing is necessary, but I’ve thrown together a quick plugin to test the idea. This is not a complete solution – flushing is a bit inconvenient, and there’s still database activity because plugins, config settings etc are loaded from a table.
Download:
http://vigilant.tv/documents/tp/zem_cache-0.1.txt
http://thresholdstate.com/download/zem_cache-0.5.txt [wet]
It’s a little rough, and probably has some bugs.
If you try it out, please post before and after runtimes to this thread.
To use it, surround a page with the txp:zem_cache tag, like this:
<code>
<txp:zem_cache><!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml” xml:lang=“en” lang=“en”>
<head>
[…etc…]
</body>
</html>
</txp:zem_cache>
</code>
note – your image directory must be writable. Cached content will be stored in images/cache.
You don’t have to cache the entire page. If you’re using more than one zem_cache tag per page, see the ‘id’ and ‘ctx’ attributes below.
The cache must be flushed manually; it won’t happen automatically when you post or edit an article. To flush the cache, append “?flush_cache=1” to any Textpattern URL. Alternatively, place a <txp:zem_flush />
tag on a seldom-used page, and load that page in your browser to force a flush.
You can check if it’s working by viewing the source of a cached page and scrolling to the bottom. There should be a message that says “fresh copy”, “cached copy” or “cache flushed”.
Supported attributes:
- timeout
Specifies the expiry time in seconds. Default is 3600. A small figure like 120 will give you some protection against heavy load, and eliminate the need for manual flushing. - id
Use this if you’re using multiple zem_cache tags per page. Each tag should have a different id. It doesn’t matter what the id is set to – a number is fine – as long as each one is different. - ctx
Use this to cache a single copy of something globally across all pages, rather than once per page. For example,<txp:zem_cache ctx="recent1"><txp:recent_articles /></txp:zem_cache>
Last edited by wet (2009-05-28 11:50:54)
Alex
Offline
#2 2004-08-07 04:41:35
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: [plugin] [ORPHAN] zem_cache: experiment
BTW: I get runtime figures around 0.017-0.018 with my front page cached, and 0.035-0.04 without.
Hardly earth shattering, but it’s an improvement.
Incidentally, Staticize 2.5 doesn’t bother caching content if the runtime is less than 0.05.
Last edited by zem (2004-08-07 10:09:50)
Alex
Offline
Re: [plugin] [ORPHAN] zem_cache: experiment
Wow. Since I’m on TextDrive (runtime of 0.11), I don’t think I need this one, but I’m going to nominate you as TXP Plug-In Developer of the Year.
Once I figure out where to do that…
TextPattern user since 04/04/04
Offline
Re: [plugin] [ORPHAN] zem_cache: experiment
Before: 0.0685, 0.0577, 0.1410 Avg: 0.0890
After: 0.0564, 0.0315, 0.0446 Avg: 0.0441
Maybe not a huge improvement but I think it will payoff in the long run.
Thanks, Zem
Offline
#5 2004-08-07 23:14:51
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: [plugin] [ORPHAN] zem_cache: experiment
I’ve uploaded a new version:
http://vigilant.tv/documents/tp/zem_cache-0.2.txt
The previous one prevented comments from working; this one fixes that. It also hooks into the admin side plugin stuff, if you’ve installed the patch, to automatically flush the cache when an article is posted or edited.
My guess is that caching won’t have a dramatic effect on run-times (not nearly as much as removing the dns lookup from the logging code). It might be effective in reducing server load, however, particularly on pages that have long article lists – this could make it worthwhile on sites with heavy traffic.
Alex
Offline
Re: [plugin] [ORPHAN] zem_cache: experiment
DUH! Disregard the post below. I need to redo my testing because I’m stupid.
<strike>I installed this plugin. There seems to be no difference in runtimes. I tested 4 separate pages, recording 10 samples per page. The numbers below represent the average of each page:</strike>
<strike>Before: 0.1450, 0.1124, 0.1270, 0.0879</strike>
<strike>After: 0.1475, 0.1011, 0.1245, 0.1086</strike>
<strike>I’m using 1.0rc3</strike>
Last edited by vaughn-taylor (2005-04-13 14:45:23)
Work until your carpal tunnel makes you cry.
—————————-
My “bloggy” TP site >> liberalrevolt.com
Offline
Re: [plugin] [ORPHAN] zem_cache: experiment
zem, this is a very nice plugin. And you are right on point with:
“It might be effective in reducing server load, however, particularly on pages that have long article lists – this could make it worthwhile on sites with heavy traffic.”
|
requests per second with zem_cache | requests per second regular |
10 | 7.7 #sec | 4.9 #/sec |
20 | 7.5 #sec | 3.9 #/sec |
(Note: The articles are quite long.)
Especially on long article-lists it saves dozens of [admittedly very short and light] queries. Currently with txp-code there are at least three additional queries made for each item in a list of articles: one for number of comments, one for real-name of author and one for the neighbouring article. For my example with 20 articles, total queries dropped from 75 (without cache) to 9 (with zem_cache wrapped around the article-tag).
Peak-Memory Usage stayed the same, since even after retrieving the cached portions from cache, the content is passed around in functions to be processed as if it might contain further txp-tags.
Note: I had to edit the code of the plugin to correct the path: I used $path_to_site instead $txpcfg[‘root’]. Maybe you can update the plugin at some point, zem?
Last edited by Sencer (2005-04-29 14:13:52)
Offline
#8 2005-04-29 15:25:14
- rob_roy
- Archived Plugin Author
- Registered: 2005-02-28
- Posts: 18
Re: [plugin] [ORPHAN] zem_cache: experiment
I’m getting an error that looks like this “Warning: unlink(/home/nomo/public_html/ve/cache/1a3b829ae3a79f11ea074fe25307ecdf): No such file or directory in /home/nomo/public_html/ve/textpattern/lib/txplib_misc.php(304) : eval()’d code on line 2031” on individual articles on ve.nomo.us.
It seems to work fine on auto.nomo.us, and even on the front page of ve.nomo.us, but individual articles bomb out. Though, I just thought of something…. turning off sgb_url_handler seems to fix it.
Zem_cache and sgb_url_handler don’t seem to play well together. Which is a shame, because I absolutely love how sgb_url_handler and sgb_error_documents work.
Offline
#9 2005-04-29 19:08:20
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: [plugin] [ORPHAN] zem_cache: experiment
Try http://thresholdstate.com/download/zem_cache-0.4.txt. Should work with RC3, and might be a little faster than the older one with PHP 4.3 and higher.
Alex
Offline
#10 2005-04-29 20:33:40
- rob_roy
- Archived Plugin Author
- Registered: 2005-02-28
- Posts: 18
Re: [plugin] [ORPHAN] zem_cache: experiment
That seems to play perfectly nicely with my other plugins. Thanks.
Offline
Re: [plugin] [ORPHAN] zem_cache: experiment
Note to the clueless like me: never, I repeat never delete the directory created by the zem_cache plugin in the TXP’s temp directory. If you do, nothing short of deleting the entry created by the plugin in the database will make the cache work again.
I just spend half on hour on this :(
Ok I’ve tested it on my frontpage, the whole page is cached with one instance of the cache. Without the cache, I have a generation runtime of ~0.11 (I’ve tested after a dozen of short refresh, so the MySQL4 cache was at work I believe). With the cache, I have a runtime of ~0.03.
My front page is rouglhy : one article_static, two small (~5 articles) article_custom_list, one recent_article, two call for mdn_count, and six misc_form. That output a final .html file around 20kbytes.
So for me, yes it work very much. I will go under prod’ soon, and let the cache on the frontpage for some time. If nothing wrong happen, I will start using it across the website with more granularity.
As always, nice work Zem.
Last edited by Jeremie (2005-05-08 15:30:13)
Offline
Re: [plugin] [ORPHAN] zem_cache: experiment
Awesome, zem!
Though it may slow down slightly, would it be possible to rewrite this a little to have it check to the database and see when the last change was made to the content of the page and at that point rewrite the cache for the requested/changed page only? This would help to keep things a little speedy in the long run because you won’t have to flush the cache completely when you make a typo change or something of that nature.
Also, I would rather that it saved the cached files to /textpattern/cache instead of /images/cache (it just seems like a more obvious place)
Offline