Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Beatnik (493)

  (email not shown publicly)

A 29 year old belgian who likes Mountain Dew, Girl Scout Cookies, Tim Hortons French Vanilla Flavoured Cappucinno, Belgian beer, Belgian chocolate, Belgian women, Magners Cider, chocolate chipped cookies and Perl. Likes snowboarding, snorkling, sailing and silence. Bach can really cheer him up! He still misses his dog.

Project Daddy of Spine [], a mod_perl based CMS.

In his superhero time (8.30 AM to 5.30 PM), he works on world peace.

Journal of Beatnik (493)

Thursday May 31, 2007
04:41 PM

Caching in web apps

[ #33390 ]
My CMS is building web pages on the fly, based on a number of components (template, navbar, macros, etc). Most of the content is semi-static. The user edits it once in a while so it can't really be a static page (the application does support mixing virtual and file-based contents already). What I was looking for was a way to still save some load time but keep the dynamic support. The hack I came up with is a bit as follows: I keep a hash in memory with all the necessary information (name, complete content data, modification time) of the contents that need caching (this is set in admin panel). I do a very minimal query from the database to check if caching is needed for the page. If so, I skip all the extras and just dump the cached content. Problems that might arise:
  1. Location collisions: Since I load a global hash, different website setups can access the same cache hash. Can be fixed easily enough.
  2. Memory: Loading pages in cache takes up memory. Depending on the approach, it might end up taking a lot of memory.
  3. Automatic renewal of cache: At the moment, content data is loaded into cache only once (on the first request). I still need a way to refresh the cache (based on edits/last modified time).
  4. Dynamic items: Page counters, for example, can't be used in the cacheable pages.

Some stats: requesting 10,000 pages takes about 80 seconds with caching and 270 seconds without caching.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.