Programmatically invalidating cached pages Naughty chatlines

views_invalidate_cache() clears ALL cached Views data, for every View on the site.How can I trigger a cache invalidation for a specific View from inside my module code?Correct me if I'm wrong, but it looks like you have to have the entire View in scope to execute this.

programmatically invalidating cached pages-15

I'm specifically looking for a way to target a Views cache with PHP from within my own module code.

Thanks for sharing this, though, it might help others. Not to second-guess you too much, but have you considered a reverse-proxy caching system like varnish? If you are able to use rules in your situation, then you don't even need to write custom code, you can just use the module as-is and set up rules to clear the caches of certain views.

Those things give incredible performance and make db caching of views, nodes, etc somewhat moot (unless you have a lot of logged-in users and need this caching for them). Otherwise, check out the internals of how it works as a guide to clearing view caches programmatically.

NET determines whether the cached output is still valid based on the cache policy you have defined in the page.

If the output is valid, the cached output is sent to the client and the page is not re-processed. NET provides you with the ability to run code during this validation check using a validation callback, so that you can write custom logic to check whether the page is valid.

The validation callback allows you to invalidate cached pages outside of the normal process of using cache dependencies.I am facing a situation where I need to invalidate a specific View in order to initiate clearing the cache on that View.Just curious :-)/** * Function to invalidate selected views caches to enable the action forms to work */ function mymodule_invalidate_views_cache($view_name) { cache_clear_all('ctools_export:views_view:' .$view_name, 'cache_views', TRUE); cache_clear_all($view_name, 'cache_views_data', TRUE); } I needed this to allow VBO actions with configuration forms to be able to work while views caching was enabled (I am using content caching).I called this twice, once in the function mymodule_myaction_form() and again in the function mymodule_myaction_submit(). It's normally used to automatically clear a views cache when related content is added or updated, however it provides a framework to monitor a cache segment.I haven't done this, but developer docs are available.

19 Comments

  1. views_invalidate_cache() clears ALL cached Views data, for every View on the site.

Comments are closed.