our drupal site has some user specific content. When we enable page caching the whole page is being cached. Isn't it possible to cache only fragments of the page. Or specify which fragments not to cache? Or even specify which pages not to cache. This way we can remove some stuff from the caches when logged in. Or don't use the cached versions when logged in.
I found this website already but it doesn't seem to work: http://www.jpstacey.info/blog/2009/03/03/how-to-not-cache-a-particular-drupal-page
But this doesn't seem to work.
kind regards, Daan
First, I second Ran Bar-Ziks suggestion of putting the 'not to be cached' data in a separate block and set that block to BLOCK_NO_CACHE
, as it is the simplest solution.
If that is not possible, you can disable caching of specific pages, but contrary to the suggestion from the link you posted, I'd do this by preventing the page from getting cached in the first place (rather than removing the cache entry afterwards).
To do this, you can manipulate the global cache config setting temporarily on the page in question:
// Disable caching for this request cycle
$GLOBALS['conf']['cache'] = FALSE;
Where you put this code depends on the pages you want to exclude from caching:
hook_view
.hook_nodeapi()
implementation.
** This would also also work for individual nodes, if you add a check for the node id before disabling the cache.hook_init()
implementation, checking for the path (or path alias) to decide whether to disable caching or not.It should be obvious that you need to clear caches first for any of these approaches to work, as they depend on preventing the page from being cached at all. They will not remove an already paged entry from the cache.
You can put the data that you don't want to be cached in block and use BLOCK_NO_CACHE to prevent this block from caching. It is very simple thing to do and explained in drupal.api: http://api.drupal.org/api/drupal/modules--block--block.module/constant/BLOCK_NO_CACHE/6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With