Score:0

Clear specific view's cache programmatically, specific to contextual filter

de flag

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).

articles/45
articles/46
articles/47

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.

No Sssweat avatar
ua flag
`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.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.