Closed (fixed)
Project:
Views argument cache
Version:
7.x-1.0-beta3
Component:
Documentation
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
2 May 2012 at 19:03 UTC
Updated:
7 Jun 2012 at 16:41 UTC
I was following your example on the project page but the example seems cut off. So with this module if you created a class and referenced a school, only the views cache for the view that shows up on that school page would be cleared?
Comments
Comment #1
mstef commentedThanks for asking - I know it's a bit confusing, and really only useful for a specific scenario. In my case, that scenario was very important and I found myself needing this in about 3-4 places on my site.
Normal views cache plugins generate a cache key like this:
view_name:display_id:type:md5_of_build_data
With a key like that, there's no way to differentiate between caches for a given argument, so usually, the entire cache is cleared for a given view and display id.
My example of that was for Views content cache. That's a cache plugin that will keep the view cached until a given node type has an add/edit/delete operation -- then the entire cache for that view is cleared.
With this module, you can target only the cache for a given view, display, and arguments.
I'll give you a working example.. Check out the calendar on this page - http://workoutspots.com/nimblefitness. That's a view that shows class nodes. The view takes an NID argument (for the location node that you're viewing) and only shows classes that are referenced to that location.
I used to use Views content cache, and whenever someone added/edited/deleted a class, I would have it flush out all of the caches for that view. But why empty the cache for all 200 locations when I know that the given class will only affect one of them. That's how this module was born...
Remember, as the project page depicts, the only way to clear caches is with custom code.
When a class is about to be saved, I called views_arg_cache_flush(), passing in the node ID of the location. So, only the cached view for that given location node is flushed -- and the rest remain intact. So you have to be careful with this module. You have to know exactly what actions will affect which views, and you have to clear them with custom code.
Now, the views cache keys look like:
view_name:display_id:md5_of_args:type:md5_of_build_data
In the beta3 release, you can pick how many arguments to generate cache keys for. This is useful because those calendars take a second argument of month/year, but I want to ignore that, so I can only pass in an NID and clear for that.
I hope that makes sense. Please ask more questions if needed.
Comment #2
mstef commentedHere's an example of the cache keys in the database for that view:
The first hash is basically just the location's node id. So when a class is added for that location, calling views_arg_cache_flush() then calls cache_clear_all() using "location_fullcalendar:block:36ba51ad84bf8a85cd2434cb7e0e7d8b" as a wild-card. So only caches pertaining to that get removed, and the rest remain.
Or, for multiple arguments
Comment #3
R.J. Steinert commentedI think I follow you. To try and sum up what you described...
What this module does: Gives you the option to choose which arguments will end up in the key of the views cache entries for that view.
What this module enables you to do: This allows you to flush views caches that have specific arguments set (ie. a node nid).
What you have to do to make this work: Use the views_arg_cache_flush() function in the appropriate place to help you flush View caches with specific arguments for the desired effect.
Comment #4
mstef commentedSounds about right to me. Why don't you try it out, then if you have problems, come back, show me your view and your code, and we'll make it work. You can select cid from the cache_views_data table to see the entries, and check if they cleared.
Comment #5
mstef commented