nukl
nukl

Reputation: 10511

Caching different types of model instances

It's possible to cache list with different types of objects in django? When i'm trying to do this, django always return None to me.

Check this code:

foo = Foo.objects.all()[:10]
bar = Bar.objects.all()[:10]
foobar = list(foo) + list(bar)
cache.set('foobar', foobar)
cache.get('foobar') # None

If this is normal behaviour, is there some workarounds?

Upvotes: 0

Views: 59

Answers (1)

okm
okm

Reputation: 23871

Django could cache such list, you need to check

  • cache.set('foo', 'bar') then get to ensure the cache works
  • the log of the cache backend to know whether set succeeds
  • for memcached backend, whether foobar is too big to fit in the cache

Upvotes: 2

Related Questions