Malcolm Tredinnick napisaƂ(a):

>> I have an interesting idea that I am not quite sure how to pursue.
>> I'm wondering if any of you have figured this out already.
>>
>> What I would like to do is set the cache expiration for a particular
>> object in the cache to be very high, and then delete the item from the
>> cache when an instance of its model is saved.  This would be
>> particularly useful for a site where the data only changes through the
>> admin interface, and not very frequently.  This way, the object can
>> stay cached as long as it has not changed.
>>
>> I was thinking of trying something with the post_save signal and the
>> cache middleware.  Has anyone tried this already?  Or is this a bad
>> idea?
> 
> The usually difficult part of this type of proposal is querysets. You
> need to find every cached queryset that contains the model in question
> and delete it as well. This essentially requires scanning every queryset
> (or coming up with a really good hash function to enable cutting down
> the search set). There was a Summer of Code project that tried to do
> this, but it didn't seem to go anywhere.

I use this approach at work and in my personal site. This works great
(and greatly reduces app response times due to not hitting db every so
often), but you have to know under what key what data is cached. I came
to idea of key registry, but it works only if your app runs in one
instance only (how to share the set that implements registry between
instances?)

Signals simplify this a bit, because they give you one centralized point
of cache invalidation, but when the number of keys grows beyond some
point it's easy to get lost.

-- 
Jarek Zgoda
Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101

"We read Knuth so you don't have to." (Tim Peters)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to