Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-05-12 00:43:47

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

asy_jpcache 0.9.8 - Fast Full Page Caching

Update: This should be ready for prime-time now.

Current Version: 0.9.8

Download:

asy_jpcache0-9-8.zip w/ fixes by net-carver.

Version History
  • 0.9.8
    • - updated installation instructions
    • - minor fixes
    • - removed statistics on read-write ratio
  • 0.9.5
    • - added option to enable txp’s logging (defaults to off)
    • - clean cache on editing links
    • - extended help section in admin-plugin
    • - added statistics on read-write-ratio in admin-plugin
    • (only if logging is enabled in jpcache and set to ‘all’ in Textpattern)
  • 0.9 (non-public release)
    • - added option to skip caching for feeds (defaults to off)
    • - skip caching of feeds if the request can result in partial content (A-IM/feed, RFC3229)
    • - skip caching when there is too little content (for example when doing redirects)
    • - added some code & explanation to hack in application/xhtml+xml support
    • - added Content-Length header
  • 0.8
    • - don’t clean cache when merely viewing or previewing articles in article-event
    • - add statistic in admin-side plugin over number and total size of the cache-files
    • - sniff content and guess Content-Type on PHP4 (see Known Issues)
    • - finally, completely fix garbled feeds. (strncmp returns 0 for a match, go figure…)
  • 0.7.1 repackaged 0.7. The admin-side plugin was corrupted and could not be installed.
  • 0.7 fixed garbled output of feeds (they were compressed twice), added a missed article hook.
  • 0.6 used headers_list (only PHP5) if apache_get_headers (only SAPI) not available
  • 0.5 initial release

Information

asy_jpcache is based on zem_cache, jpcache and some ideas from WP-Cache.

asy_jpcache will only cache complete pages (including your feeds). If you want to cache partial pages to retain some dynamic parts take a look at zem_cache which is perfect for that kind of thing.

Installation

  • 0. Use Textpattern 4.5+
  • 1. Copy the directory jpcache and its contents into your main directory. It should be right next to your images and your textpattern directory (on a default install).
  • Make sure that the jpcache/cache directory can be written to. Usually chmod 777 jpcache/cache/ will do the trick.
  • 2. Edit your config.php in the textpattern directory and before the closing ?> insert the following line: $txpcfg['pre_publish_script'] = './jpcache/jpcache.php';
  • 3. Don’t forget to activate this Admin-plugin.
  • 4. Optional: Look inside jpcache/jpcache-config.php to change a few settings, like enabling Debugging, permanently turning off gzip-encoding, change timout etc.

If you are experiencing problems (or want to deactivate jpcache), comment out the line in your config.php that you added: //$txpcfg['pre_publish_script'] = './jpcache/jpcache.php';

Details about how JPCache works

Note: The files you received are a modified version of the original jpcache available at jpcache.com. Do NOT use this modified version for other stuff, please use the original jpcache version, because this here was hacked to serve textpattern.

After a user requests a page, JPCache will save the result-page in compressed format in the cache-directory. For subsequent requests, JPCache will
  • not serve a cached page, if the latest cached file is older than X seconds (default 900)
  • send a 304 header it ETag-headers are set
  • otherwise send the compressed page if gzip is supported
  • or sent the uncompressed page if gzip is not supported
  • delete a cached page, if a comment is posted at that URL
asy_jpcache will also automatically clean the cache when
  • comments are edited, deleted, moderated (for this and the following activate this plugin)
  • articles are edited, posted, deleted
  • forms or pages are edited.

asy_jpcache will not cache requests made via POST (like comment previews).
asy_jpcache will not cache file-downloads.
FAQ

I have Problems with my Feeds
There have been reports that some people have occasionally problems with the RSS/Atom-Feeds. I was not able to reliable reproduce them to find a fix. I have implemented a few things in 0.9 that should solve those problems. If you do however have problems with Feeds, please report so in the Forum. In the meanwhile you can easily turn of caching of the Feeds in jpcache-config.php by setting $JPCACHE_SKIP_FEEDS to 1.

My Textpatterns access logs keep getting shorter
That’s a good thing, because when cached files are served it is usually not recorded in the db. However if you wish to keep recording hits in the db set $JPCACHE_TXPLOG_DO to 1. Now when cache-reads are recorded to the db, jpcache will add “#cachehit” to the url. (Default is off, because cache-reads require no access to the db. Enabling this will lower performance a bit.)

I am using the XRT-Plugin
If you are using the XRT-Plugin (XML-RPC for Textpattern) by pixelmeadow, you are basically posting content to your blog without going through the Admin-Interface. Therefore the cache will not be cleaned right away. Due to the fact, that cache is periodically regenerated (default time 900 seconds), your changes may appear up to 900 seconds later on the actual site. You can shorten the default caching time in jpcache-config.php.

What happens with CSS-Requests
The stylesheets are not affected by jpcache, because they are served from a different file (not index.php). Since stylesheets usually do not change, my advice would be to put them in a regular (static) file and let the Webserver handle it (it’s more efficient).

Content-Type on PHP4
If you are using PHP4, asy_jpcache cannot get and cache the proper Content-Type of the generated page. The current workaround to this, is to take a look at the first 50 characters of the content and decide wether it’s a rss-feed, xml-feed, or text/html. This is fine for most Textpattern users. If for some reason you want to change those hardcoded headers or add more, take a look at $JPCACHE_DEFAULT_MIMETYPE in jpcache/jpcache-config.php and maybe the code in jpcache/file.php below the Line saying:
//Content-Sniffing to set correct Content-Type, because headers were not available

I am serving application/xhtml+xml sometimes
(This assumes you already have a plugin that handles this like phw_DTD )
If performance is really, really important, then don’t, because it complicates caching and lessens its benefits (at least the way it is implemented here). Otherwise:
If you are using PHP 5 simply open jpcache/jpcache-config.php and set $JPCACHE_XHTML_XML to 1. This will add the Accept-Header to the caching-key, meaning that for each URI one cache-file for every different Accept-Header will be written. Done.
If you are using PHP 4 in addition to the above you will also have to change the code that decides which Content-Type Header to send. There must be a line that is similar to header(“Content-Type: application/xhtml+xml; charset=utf-8”);. Add another line right there that sets the variable
$GLOBALS[‘JPCACHE_DEFAULT_MIMETYPE’] to something like “application/xhtml+xml; charset=utf-8”. That way, JPCache will know which Content-Type to associate with the request.

Original downloads: asy_jpcache0-9-8.tar.gz and asy_jpcache0-9-8.zip

Last edited by wet (2012-10-06 06:58:43)

Offline

#2 2005-05-12 01:36:45

soulship
Member
From: Always Sunny Charleston
Registered: 2004-04-30
Posts: 669
Website

Re: asy_jpcache 0.9.8 - Fast Full Page Caching

Saaaweet! Nice work… I am off to give this a spin. Thanks!

Offline

#3 2005-05-12 02:12:25

Etz Haim
Archived Plugin Author
From: Karlstad, Sweden
Registered: 2005-01-24
Posts: 262
Website

Re: asy_jpcache 0.9.8 - Fast Full Page Caching

Can’t get it to work. Although I’ve done:

chmod 777 /path_to/public_html/jpcache/cache/

I get the followind debug headers:

HTTP/1.1 200 OK
Date: Thu, 12 May 2005 02:01:04 GMT
Server: Apache
X-Cache: asy_jpcache v2 – file
X-CacheDebug-1: Cache scriptkey is set to /article/19/balibar
X-CacheDebug-2: Cache varkey is set to GET=a:0:{}COOKIE=dcca48101505dd86b703689a604fe3c4
X-CacheDebug-3: Cachekey is set to 82470b2f5369c9cba6cef5dd27ecef4b
X-CacheDebug-4: Failed to open for read of /path_to/public_html/jpcache/cache/jpc_82470b2f5369c9cba6cef5dd27ecef4b
X-CacheDebug-5: Invalid content of cache-file /path_to/public_html/jpcache/cache/jpc_82470b2f5369c9cba6cef5dd27ecef4b
X-CacheDebug-6: No (valid) cachedata for 82470b2f5369c9cba6cef5dd27ecef4b
X-CacheDebug-7: Callback happened
X-CacheDebug-8: Writing cached data to storage
X-Powered-By: The blood, sweat and tears of the fine, fine TextDrive staff
Served-By: TextDrive
Connection: close
Content-Type: text/html; charset=utf-8

and the following content:

<notextile><html><body></body></html></notextile>

Last edited by Etz Haim (2005-05-12 02:12:50)

Offline

#4 2005-05-12 07:15:25

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: asy_jpcache 0.9.8 - Fast Full Page Caching

Is your Textpattern installed in the root directory?

According to the Debug-Output, a cache is not found, so the page should be generated and saved to disk. When you look inside the directory, can you see the file jpc_xxxxx? Do you always get the same output, even after requesting the same page several times?

edit: Hold on, I can’t get it to run on textdrive either. I’ll check it, and get back to you…

Last edited by Sencer (2005-05-12 07:34:23)

Offline

#5 2005-05-12 07:19:48

Etz Haim
Archived Plugin Author
From: Karlstad, Sweden
Registered: 2005-01-24
Posts: 262
Website

Re: asy_jpcache 0.9.8 - Fast Full Page Caching

In the directories listed above, public_html is my virtual server root. I’ve looked inside the cache directory and never found any file at all.

Offline

#6 2005-05-12 10:09:43

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: asy_jpcache 0.9.8 - Fast Full Page Caching

Ok, obvious one. To store the correct headers (text/html vs. application/rss+xml etc.) I am calling apache_reponse_headers(). This is only available when PHP is running as an apache module. Instead use headers_list();

—You have to edit jpcache/file.php on line 220:—

—I will update the plugin-download later.—

Ok, I updated the plugin. Please download version 0.6 (link above).

Last edited by Sencer (2005-05-12 12:45:40)

Offline

#7 2005-05-12 18:44:19

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: asy_jpcache 0.9.8 - Fast Full Page Caching

—I somehow ommitted the hook for creating articles.—
—I’ll let you know when the plugin is updated…—
—-
—Another Problem: Feeds are already gzipped by textpattern, compressing it twice leads to garbage. For now, if you are using this plugin it is better to set GZIP to 0 in—

Ok, Plugin updated to Version 0.7 and issues are fixed.

Last edited by Sencer (2005-05-17 15:02:57)

Offline

#8 2005-05-17 15:25:31

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: asy_jpcache 0.9.8 - Fast Full Page Caching

Ok, the plugin is now updated to version 0.7.

It should be mostly bugfree, and also regular users are welcome to try out this plugin.
Please install and report any experiences you have with it.

<hr>
Here is a current benchmark.

Setup:
Server: Celeron 1,7Ghz; 512MB RAM; Ubuntu Linux; Apache2, mysql4.0, php4.3 with eaccelerator
Client: Pentium 933 Mhz; 256MB RAM
Network: Switch Zyxel 660HW; 100MBit
Test run: ./ab.exe -c10 -k -n1000 -H ‘Accept-Encoding: gzip;’ http://local.testsite.de/
(Index-Page with a list of 10 relatively long articles)

Without Cache:
Requests per second: 7.69 1 (mean)
Time per request: 130.087 [ms] (mean, across all concurrent requests)

With Cache:
Requests per second: 178.00 1 (mean)
Time per request: 5.618 [ms] (mean, across all concurrent requests)

Last edited by Sencer (2005-05-17 15:37:28)

Offline

#9 2005-05-17 19:39:13

ArbinShire
Member
From: Tallahassee, FL
Registered: 2004-03-23
Posts: 31
Website

Re: asy_jpcache 0.9.8 - Fast Full Page Caching

Without Cache:
Requests per second: 7.69 1 (mean)
Time per request: 130.087 [ms] (mean, across all concurrent requests)

With Cache:
Requests per second: 178.00 1 (mean)
Time per request: 5.618 [ms] (mean, across all concurrent requests)

Holy shimmy….. I definitely need to check this out.

Offline

#10 2005-05-17 20:01:34

edburdo
Member
Registered: 2004-09-20
Posts: 79
Website

Re: asy_jpcache 0.9.8 - Fast Full Page Caching

Nice… now how can I go about testing the cache to see what sort of speed boost I get?

Visually, it looks faster. :)


Eric

Offline

#11 2005-05-17 22:18:19

jbrew
Member
From: Imperial Beach, California
Registered: 2004-03-04
Posts: 78
Website

Re: asy_jpcache 0.9.8 - Fast Full Page Caching

The Admin-plugin is all screwy and wont install… anyone have a version that will?


To even the least of these…

Offline

#12 2005-05-17 22:19:58

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: asy_jpcache 0.9.8 - Fast Full Page Caching

Currently there is really no way to do that. Your best bet is to run apache bench on your development machine. The numbers that can be retrieved from within php with microtime etc. are pretty unreliable, but if there is demand, I may add an additional http-header field with the info at some later point. Remember that apart from speed, you are also relieving your db-server and reducing the memory-usage on the machine.

Last edited by Sencer (2005-05-17 23:17:27)

Offline

Board footer

Powered by FluxBB