The Automagic Speed-Up Cache
Feature
Motivation
The granularity of cache expiration in Drupal has been a long-standing problem.
One can have the most effective cache in the world, but if it clears entirely on any content change, it is not really workable. A “page” in Drupal can have blocks, listing, entities, regions, and many other objects. When one contained item changes, the container of that item needs to be fully rebuilt; often, that is the whole page, a problem requiring a much-needed solution.
Why can't we just rebuild the parts that have actually changed?
Consider what would be the best case scenario here. Assume that every item listed above can be cached separately. Now if one single entity changes, the following would be our "perfect" page request:
- Drupal bootstraps.
- Drupal builds the page.
- Drupal notices that only the “content” region has changed and retrieves the remaining regions from cache.
- Drupal re-builds the content region.
- Drupal notices only one listing in the content region has changed and retrieves the remaining blocks from cache.
- Drupal builds the “missing” block.
- The block contains a listing of entities.
- Drupal re-builds the listing, and entity_view() is called on these entities.
- Drupal retrieves all entities except the changed one from cache.
We would have a bootstrap, then we would see just one region call, one block call, one listing call, and one entity building call. Is this really possible?
Yes and no.
There are certain implementation limitations – especially around page assets – and a unified caching strategy needs to take them into account.
State of the Art
Render Caching is the saving of HTML content in a storage cache, while retaining assets like CSS and JS files and other “out-of-band” data. It can be used for reconstructing the page content, without changing the state the page would have without render caching active. The render cached HTML markup needs to be removed from the cache, or updated in the cache when the objects used for generation of the markup change.