I've been trying to figure out the caching system of views as I have a very heavy query that takes a long time to load (3-4 minutes). With caching set it loads in a few seconds.
The problem is, it seems that caching is done on a per-session basis. I tested this by setting one of my smaller static views to cache for one hour, then hitting the page with that block with different browsers on different connections. The cache_views_data table got a new row for each anonymous user that loaded the view. Once there, repeated visits didn't create any new rows, and using the devel module for my admin hitting the view I could see that on subsequent visits it was using the cache.
See the attached pic, that's two anonymous users hitting the same view, creating identical sized cache with a different cid. I read somewhere that caching should be by role which makes sense, by session doesn't seem like it would do much for resource savings.
Comment | File | Size | Author |
---|---|---|---|
#10 | multilingual_cache_fix-1426624-5555116.patch | 1.1 KB | beck24 |
views_cache1.jpg | 32.73 KB | beck24 |
Comments
Comment #1
merlinofchaos CreditAttribution: merlinofchaos commentedThe following is the exact criteria used to generate the cache key:
You can find this in the file views/plugins/views_plugin_cache.inc
If somehow the query ends up dependent upon session data, then that would indeed happen.
You might want to put some debug in that area of the code and see what's causing the cache key to turn up different.
Comment #2
beck24 CreditAttribution: beck24 commentedThanks for prompt reply and the useful info. I'll set some debugging code and let you know what I come up with.
Comment #3
beck24 CreditAttribution: beck24 commentedI hadn't had a chance to debug yet as I posted that at the end of the day, but I looked at the query - the only part that could possibly be session related is the filter "published or admin" - do you know offhand if that's what I should look at?
Comment #4
beck24 CreditAttribution: beck24 commentedI var_dumped $key_data on both anonymous users. Everything is identical up to this point:
Anon User 1
Anon User 2
Any idea why the language (the same language no less) would show up differently for anonymous users?
Comment #5
beck24 CreditAttribution: beck24 commentedOk, I've sorted it out.
The site is multilingual, and has the language switcher block active, and authenticated users can set a default language for their account.
For some reason there are multiple language states per language. For anonymous users, they have one setting for using the site default language when they land on the page. If at some point they switch languages with the language switcher, and switch back, they have a different setting of the same language which creates a new cache.
Authenticated users have 3 states of language:
Site default
Language Switcher
Account default
So it's not as bad as I originally thought. Caching on this system isn't per session, it's per role per language type. Which is redundant in many cases, but I can live with it.
I'm assuming this falls under "working as designed" so I'll set it as such. If in fact this isn't as designed feel free to reopen it.
Thanks for your help Merlinofchaos.
Comment #6
beck24 CreditAttribution: beck24 commentedComment #7
merlinofchaos CreditAttribution: merlinofchaos commentedIiiinteresting. It's encoding an object id when we serialize the language.
Ok, I think the answer is that we need to just do $language->language not the entire object.
This was a change from D6 to D7 that maybe didn't get updated in the port.
Can you modify
Into
You'll need to do it in 2 places (the result key and the output key are generated separately).
If that works for you, can you post a patch?
Comment #8
merlinofchaos CreditAttribution: merlinofchaos commentedLet's mark this active just long enough to see if my proposed fix helps.
Comment #9
beck24 CreditAttribution: beck24 commentedYes, that makes sense, and indeed it does work.
I'll see if I can remember how to do a patch (it's been a while)
Comment #10
beck24 CreditAttribution: beck24 commentedPatch attached.
Comment #11
dawehnerThis change looks fine. Thanks for the patch!
Committed this change to 7.x-3.x
@beck24
Next time set the status to "needs review" so people will see that you have posted a patch.
Patch(to be ported) is for a patch which was written against a certain version but NOT yet against another.