Download | Overview | Comparison of caching methodologies | Benchmarks | Contact


Note: Right now, Cache::Static is of limited utility, as it only has limited support for DBI type dependencies - this support will be added before version 1.0, but in the meantime, only file, XML::Comma, and time dependencies are fully supported.

Also, it appears someone claimed the name "static caching" before I did, for a very different idea. Bummer. If you are interested in that work, not this perl module, click here

Download

The current release of Cache::Static is version 0.9904 - old versions can be found here. Or you can browse or check out code from our subversion archive at https://chronicle.allafrica.com:8080/repository/trunk/Cache-Static/. A changelog is also available.

Cache::Static is production quality software, and is in use on high-traffic sites such as Media Matters for America, AllAfrica.com, and various websites used by the Tactical Technology Collective.

Overview

Cache::Static is a perl module that allows for the substantial load reduction of caching software without the delay in freshness necessitated by time-based caching software.

Cache::Static allows the developer to specify what sorts of dependencies (files, database rows, XML::Comma docs, times, etc.) are associated with a given calculation (typically a webpage or component thereof). If none of the dependencies have been modified, Cache::Static returns the last result of that calculation. If, however, any of the dependencies are found to have changed, the output of the calculation may change, and Cache::Static lets the software re-calculate, inserting the new value in its cache.

Cache::Static excels under extremely heavy loads, but it also does better than (or complements) time-based caching when either a) resource intensive pages are loaded seldom (and a traditional cache has already expired) or b) pages are not easily broken into sub-components (or reverse proxies are invalidated by cookies). This approach can save resources regardless of workload type.

There are two basic approaches to reducing load in a write seldom, read often environment like most websites. The first is traditional time-based caching, with which I'll assume the reader is familiar. The second is to write dynamic output to disk so it can be served by a static web server; simultaneously tracking dependencies, re-generating all relevant pages when a dependency changes. Cache::Static represents a new approach, combining the best of these two worlds, with a methodology creatively (ahem) called "static caching". A comparison of these approaches follows:

Comparison of caching methodologies

Time-based Caching

The good:

The bad:

Dependency-based Re-generation

The good:

The bad:

"Static Caching"

The good:

The bad:

Static caching performance worsens only infinitesimally as the frequency of reads increases because the only calculations needed are few file stat()s and an md5sum.

Cache::Static excels under extremely heavy loads, but it also does better than (or complements) time-based caching when either a) resource intensive pages are loaded seldom (and a traditional cache has already expired) or b) pages are not easily broken into sub-components (or reverse proxies are invalidated by cookies). Thus, the Static Caching approach saves resources regardless of workload type.

Static Caching (as implemented by Cache::Static) is the right solution for a wide variety of optimization problems - however, it is not the solution to all problems. Most sites that use Cache::Static, in fact, use a combination of static caching and time-based caching.

Benchmarks

Load on Media Matters' backend web server, with and without Cache::Static enabled. These tests were done at around 2pm on a weekday, which is when the site has near peak traffic. Methodology was: enable/disable Cache::Static, wait 15 minutes, get load statistics.
Load1 min5 min15 min
enabled0.520.540.50
disabled3.923.632.49
enabled0.370.551.25

The trial with Cache::Static disabled actually had to be aborted before 15 minutes had elapsed because the site was loading noticeably slower - indeed, Cache::Static keeps MMFA from having to invest in additional hardware, Load on the home page (which has numerous complex iterators and log file parsing to determine whch items are most read) was benchmarked to be a whopping 30 times slower without Cache::Static! Furthermore, traditional time based caching is impossible for this site because there is user-tailored content on the front page, and a proxy-cache defeating cookie. Despite all this, Cache::Static renders the page quickly, and wth no loss of user information or delay in freshness.

Another test was done at night (with lower overall load levels), and the difference was just as stark:

Load1 min5 min15 min
enabled0.330.300.35
disabled1.041.040.91
enabled0.100.130.40

Significant savings in load were also realized on the database server in both tests (although they were not recorded). In addition to the load savings, certain pages loaded up to 20 times faster with Cache::Static enabled. Note that traditional caching methods were left enabled during the course of this test (HTML::Mason's caches, a reverse proxy-caching webserver with page timeouts, and various other caching methods were still in use when Cache::Static was disabled).

Contact

For questions, patches, etc. please contact scache@allafrica.com


Download | Overview | Comparison of caching methodologies | Benchmarks | Contact


Back