Django default cache
Question:
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 ?
Answers:
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
Empirically
>>> from django.conf import settings
>>> settings.CACHES
{'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
>>>
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',
}
}
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 ?
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
Empirically
>>> from django.conf import settings
>>> settings.CACHES
{'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
>>>
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',
}
}