Greetings from SF!

Here's a bit from one of our internal projects. Does something like
this already exist? If so, does it work well? If not, would anyone be
interested in this? We now have this working (well, at least limping)
with Django 0.96 and memcached.

MOTIVATION:
- Suppose the following is very expensive:

    MyStuff.objects.filter(<conditions>)

We commonly use caching to avoid doing this operation often, which can
leave our code littered with the following:

    cached = cache.get(<cachekey>)
    if cached:
        return cached
    else:
        x = MyStuff.objects.filter(<conditions>)
        cache.set(<cachekey>,x,<time>)
        return x

We seek to unify the Django ORM and caching in a natural way.

USE CASES:
- To cache QuerySets, append .cache(<time>) to the end of the Django
ORM call. This will cache the given object for <time> seconds provided
that the cachekey is not already in the cache.
  - Example: MyStuff.objects.filter(extra_type=4).cache(3600)
  - This should return all MyStuff objects with an id greater than 10
    and should store the result to the cache for 3600 seconds (1
hour).
- To force caching (even if the cachekey already exists), provide the
force argument (e.g., .cache(<time>,force=True)).
  - Example: MyStuff.objects.filter(mass=20).cache(3600,force=True)
  - This should return all MyStuff objects with a mass of 20 and
should
    cache the result for 3600 seconds even if it would over-write a
    previously-cached result.
- To ensure that a cached value is not used, use .nocache() before any
specific call.
  - Example: MyStuff.objects.nocache().filter(user__id=7)
  - This should return all MyStuff objects with a User whose id is 7
    and should not use a previously-cached value even if it exists.

Thanks in advance!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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