I am using the following to clear view specific cache on node_presave which is working fine.

  cache_clear_all($view_name.':'.$display_name, 'cache_views_data', TRUE);

Currently, it is deleting all the views generated for all Contextual Filters(taxonomy term id). I want to be able to delete only the view for one taxonomy term id.

For example, if the node a with tid:46 is added,

What is happening: All the following view's caches are cleared(deleted from cache_views_data table).


What I want to happen: only delete the view's cache for articles/46.

So, to achieve this I started digging into the tables(mainly cache_views_data) to figure out the pattern of the CID.

There is a UUID like string added to each CID.

enter image description here

What I have known so far is: that this String seems to be the same for a particular view. For example, for the view articles/46, it is the same each time. I have tried clearing the cache several times and re-generate it again and again.

I believe that if I can know the correct string for each view, I can clear the caches specifically. So my question is: Is what I am trying to achieve doable? Does the string change based on some unknown factor? If not, is it consistent and dependable? If yes, then how can I know how and where is this generated?

My guess is that the views module is using the ctools module for this but I don't know how exactly.

  • I can clear the caches specifically, Is what I am trying to achieve doable? I fear not or at least not without some major work. As I'm sure you know, cache tags were introduced in D8 exactly for this purpose. If it was this simple for D7, I'm sure it would've been added a long time ago.
    – No Sssweat
    Apr 3 at 3:09


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.