On Sat, 2007-06-09 at 14:52 +0000, Henrik Lied wrote:
> Hi there!
> 
> I haven't found anything on this, so I thought I'd ask:
> Has anyone implemented event-based caching in Django?
> 
> Hypothetical scenario
> -------------------------------
> A rather large social networking site uses memcached for caching. The
> Django Caching Framework only allows time-based caching:
> 1. User A logs in
> 2. User A updates a blog post
> 3. User B shortly after reads the blog post, but the caching framework
> still displays the old version of the entry.
> 
> --------
> How can I prevent this? Is there an easy way to delete a single key in
> the cache?

Deleting a single key is easy -- have a look at the low-level API
section in the caching docs. The hard part is working out which key(s)
you want to delete. Since the keys used by the caching middleware are
generated from request URI and headers, you would need to be able to
work out all the possibilities and invalidate them individually.

So, if you are just using the caching middleware, the pragmatic answer
is "don't try to do this". It is implicit in the caching middleware
setup that pages may be up to N minutes out of date, so user B just has
to wait a little longer before seeing the updated information.

If you want finer grained control, don't use the caching middleware (or
don't use it solely) and cache the information you want directly, using
the low-level API. Then you can retrieve the cached info fairly easily
in your view to reconstruct the response and also invalidate the right
pieces when they are updated. This takes a bit more work, but that makes
sense, since you are wanting very fine-grained control in this sort of
setup.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
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