0

I am using Django's local memory cache in development and I can't get it to work. I have set the following in settings.py:

CACHES = {
 'default': {
             'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'
  }
}

I see the views are being called everytime a page is loaded. I only have one Django server process running in dev

Anupam
  • 14,950
  • 19
  • 67
  • 94

1 Answers1

1

Next step is to use the cache (by setting up a per-site cache, per-view cache etc.). For example to cache the entire site, use the following middleware in settings.py:

MIDDLEWARE = [
    'django.middleware.cache.UpdateCacheMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.cache.FetchFromCacheMiddleware',
]
Anupam
  • 14,950
  • 19
  • 67
  • 94
  • Hey, I am using per site caching but the cache does not get updated before expiration if any data is added/deleted/updated? This doesn't take care of it automatically? – reindeer Dec 19 '21 at 07:33
  • @reindeer no thats the idea of cache. It will use the cache until the cache expires (unless we refresh the cache) – Anupam Dec 20 '21 at 05:14