Attached patch implements ideas I described at http://cyrve.com/node/7. The patch is incomplete - Id like some feedback soon though.
I introduce a simple pattern that drupal_render() elements may use to skip any complex building that they might have to do. drupal_render() itself is not changed. We merely take advantage of the existing #pre_render and #post_render callbacks to retrieve from cache and save to cache as needed.
The patch converts the 'Recent blog topics' block to this new pattern (recall that block content may now be a renderable array). In practice, this blog block is quite fast so I will soon convert the intensive forum blocks instead of blog block. I am blocked by #394116: DBTNG Forum.module.
One major advantage to this cache strategy is that works even for sites that use a node_access module. Thats possible because our cache key actually contains the query that generates the node listing. Users who are in different groups or in different roles or whatever your node access criteria are, will see a different query and thus their cache keys will differ. This terrific idea is borrowed from eaton's new caching plugin for Views.
This patch mimics standard block cache in that the cache is expired whenever a new node is posted. It is really simple to let admin override that logic with a time based expiration. I will add that option on the the block configure page.
I decided to add a new block cache constant called BLOCK_CACHE_CUSTOM which behaves just like BLOCK_CACHE_NONE in every way. It is just a signal to code readers and DB table readers that a given block implements its own render cache.
- The cache key needs to include language and theme. Possibly move _block_cache_id() from block module to common.inc and reuse that.
- Refactor selectQuery::execute method so I can get $query after it has been altered but before it has been run.
- Revert blog changes and instead convert both forum blocks. These blocks will have tests as part of #394116: DBTNG Forum.module so no new tests are needed.
- Refactor the block cache so it uses this new pattern. This is a minor consistency win so we will see if I can get to it.