I have a Drupal 6 website and I want to write a module that will cache nodes based on the published date. Older nodes would be cached longer than newer nodes. I plan to use cache_set(), cache_get() and nodeapi hooks to add the node to the cache and check if it is in the cache before loading. However I am not sure if my logic is correct. Can provide any tips to put me on the right track?
-
I think by default your content will be cached.– MathankumarDec 29, 2012 at 10:39
-
I know the content will be cached by default by Drupal but I want to cache each node variably based on the published date. I am guessing that I should simply use a cache expire time on each node using a hook. Just not sure which hook to use.– BinnyDec 29, 2012 at 12:53
-
what exactly are you trying to cache here? the page cache contains all of the markup of an entire page, eg, the the css and js declarations, and the entire html of the page which includes all the usual page headers and blocks and so forth. Nodes, on the other hand, include just the content of that specific node, and, if you are going to be using nodeapi() hooks, all the heavy lifting database wise has already been done, unless the rendering of that information into html is huge. But then at that point, you certainly could do caching much like how block caching is done.– JimajammaJan 3, 2013 at 13:53
1 Answer
Boost could do this. Core can not due to the cache_page bin/table getting cleared on cron & node save. Boost has a cache expiration block that allows for different cache lifetimes.
-
Boost seems to be a good candidate. Thanks for the help. Still Boost does not have a central configuration page where we could set the expiration time of nodes based on factors like node published date.– BinnyDec 31, 2012 at 3:36
-
This is correct. That is why I used "could" and not "can" in the first sentence :) With boost it is technically possible and it shouldn't be "hard" to program; problem is the code to make your request happen hasn't been written. Dec 31, 2012 at 6:15
-