14

I'm importing and using cache as this:

from django.core.cache import cache
cache.add('a','b',60)

I haven't defined any settings for the cache in settings.py ,then where does this cache come from and where is it stored.

Django documentation says: "This object is equivalent to caches['default']", but what is the default ?

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
rajat
  • 3,415
  • 15
  • 56
  • 90

3 Answers3

15

In https://docs.djangoproject.com/en/stable/topics/cache/#local-memory-caching says:

Local-memory caching

This is the default cache if another is not specified in your settings file

updated dead link

phoenix
  • 7,988
  • 6
  • 39
  • 45
obayhan
  • 1,636
  • 18
  • 35
  • 3
    To add on to this, local memory caching is per process. So, this cache wont work for all the instances of your application. Only for the current one. – xssChauhan Oct 03 '17 at 09:02
8

Empirically

>>> from django.conf import settings
>>> settings.CACHES
{'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
>>> 
dani herrera
  • 48,760
  • 8
  • 117
  • 177
1

By default, Local-memory caching is used which is one of django caches.

So, because Local-memory caching is default, you don't need to write the code for Local-memory caching to "settings.py" as shown below unless you use multiple local memory caches:

# "settings.py"

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
        'LOCATION': 'unique-snowflake',
    }
}
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129