I would like to cache a node individually based on the published date of the node. Older nodes could be cached longer than newer nodes. I thought I could cache using cache_set individually but realized that nodes are cached by default and so it could be better to set an expiry time on the cache. Any thoughts on how to do this? A hook perhaps?
Share
Drupal does not have a node cache per se. If you have the page cache turned on for anonymous users, the cahced data for nodes is likely spread across three tables:
cache_content
cache_filter
cache_page
I don’t know of a way to dictate exactly when these cache rows expire, so you would have create a function
If you want to clear all caches for specific nodes based on custom rules, you could use a cache_clear_all function within HOOK_cron to accomplish that. You would first need to determine which nodes meet your criteria for cache deletion, then you could use cache_clear_all with a ‘cid’ wildcard parameter. Something like (this would go inside a HOOK_cron function in your custom module and requires that a proper cron job is set up):
I think the main point here is that it’s quite difficult to override Drupal’s build-in cache expiries.