I've views which list the list of node details. I've set views cache for 30 mins.
I want to clear particular views cache when insert a node. I've tried below code to clear cache but there is no difference in my page.

function phponwebsites_node_insert($node) {
 if ($node->type == 'tasks') {

3 Answers 3


The next snippet should work for you

cache_clear_all('MY_VIEW_NAME:', 'cache_views_data', TRUE);

Try this to clear your view display cache.

$view = views_get_view('VIEW-NAME');
$cache = $view->display_handler->get_plugin('cache');

See cache_clear_all function. Try this if you need to clear only views cache :

cache_clear_all('*', 'cache_views', TRUE);

Edit : Try Cache Action module. It depends on Rules module.

Cache actions provides rules actions for clearing drupal caches.

It currently provides actions for:

Clearing Drupal cache bins Clearing CSS/JS cache Clearing The cache of specific views Clearing The cache of specific panel pages Clearing The cache of specific mini panels

  • I've tried your code in my hook_node_insert() but it didn't clear cache for views
    – Guru
    Commented Jun 29, 2015 at 6:00
  • Just try cache_clear_all(). Commented Jun 29, 2015 at 6:09
  • If i used cache_clear_all(), then all caches are deleted. Thats why i need to delete only views cache
    – Guru
    Commented Jun 29, 2015 at 6:11
  • Ok then try to change it to cache_clear_all(NULL, 'cache_views', TRUE);. Commented Jun 29, 2015 at 6:13
  • Sorry. i've used this also. but views cache is not cleared
    – Guru
    Commented Jun 29, 2015 at 6:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.