Memcache works on localhost (without anything in settings.py)

360 views Asked by At

My question is "can anybody corroborate or explain?" The following caching logic works as expected on localhost, but fails on heroku (queries every time):

from django.core.cache import cache
QUEUE_KEY = "queue"
def index(request):
  queue = cache.get(QUEUE_KEY)
  if not queue:
      queue = QueueItem.objects.order_by("id")
      cache.set(QUEUE_KEY, queue)
  c = {'queue': queue}
  return render_to_response('index.html', c)
1

There are 1 answers

0
Sascha Trifunovic On

The cache works on localhost because Django uses local memory caching per default as described in the documentation.

I am assuming you followed this guide but did not configure your CACHE in your settings.py to use the MemCachier add-on. I just did the same and yes, it does not use the cache on Heroku. To answer @dahrens comment, there is no error. I am assuming that Heroku just disallows local memory cache or mocks it to always return empty.