Advanced Performance Techniques
Show me the cache
We have already covered CSS/Javascript cache. Caching can also be used for common database queries and also for compiled versions of scripting languages, etc. For example, Zend produce a PHP compiling module.
At Box UK, we also implement what we call 'layered caching' - that is, caching at various architectural levels. At the highest level, we keep track of database update times for each table. Assuming no personalised, rotating or random content, you can then cache each request for a dynamic page based on a combination of GET and POST variables. If the database times have not been updated since the last (cached) request, you can return the fully cached page without needing to dynamically extract the page.
At the next level, for XML/XSL based systems, the actual XSL transformation can be cached - given an XML and XSL string, take a hash of each, and cache the resulting transform against these hash strings. On each subsequent request, you can then check the hashes against the cached values, saving valuable processor power by removing the transformation process for previously transformed XML/XSL.
At a lower level, for modular systems, modular processes can be cached. Given a module for a specific page, the output from the module (or indeed the serialized object code) can be cached on the filesystem or in the users session (depending on whether you want site-wide caching or per-user caching). On subsequent requests, the date/time of this cache can be checked against database update times - if the cache is more recent than the latest database update, then use the cache.
At a lowest level, individual functions and methods within the code can 'cache' (remember) commonly called algorithms - use static variables within functions, and class properties within objects. These can then be checked for a value before processing the algorithm; if a value already exists, use the value rather than the algorithm.
Document Index
- Introduction
- Style over Substance, not Style with Substance
- Validation’s what you need, if you wanna be a record breaker
- Compression solves depression
- You thought Vanilla Ice was a bad Wrapper?
- Body Beautiful
- Back to basics
- Just because you know HTML, there’s no need to get carried away…
- Database optimisation
- Static over dynamic
- Show me the cache
- Conclusion
