1

I was wondering if there is a way to cache querysets to memcache on a site that has authenticated users and users that are not authenticated.

Basically I just need to cache queries from one table.

Any ideas would be great.

Thanks

icebox3d
  • 449
  • 7
  • 17

1 Answers1

0

Check out johnny-cache. This worked great for us until we did so much writing (updating records) that we were invalidating cache constantly. At that point we just started using memcache directly, like this.

cache.set("some_unique_key", my_queryset, 3600)
cache_object = cache.get(cache_key)

If you're dealing with large querysets or objects, you might want to pickle them first.

cache.set("some_unique_key", zlib.compress(cPickle.dumps(cache_object), 1), 3600)
zipped_cache_object = cache.get(cache_key)
if zipped_cache_object:
    cache_object = cPickle.loads(zlib.decompress(zipped_cache_object))

Django's Caching Docs

scoopseven
  • 1,767
  • 3
  • 18
  • 27
  • Looks like what I need (johnny-cache) however it is not working in 1.6 and I see its an open issue on github – icebox3d Aug 19 '14 at 20:46
  • If you're just looking to cache a single table, use memcache directly. Are you trying to cache calls to a django built-in like auth_user or are you looking to cache something you've built yourself? – scoopseven Aug 19 '14 at 23:22