Django default cache
Asked Answered
F

3

16

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 ?

Felon answered 31/7, 2014 at 6:35 Comment(0)
K
17

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

Kneehole answered 31/7, 2014 at 6:46 Comment(1)
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.Inset
F
9

Empirically

>>> from django.conf import settings
>>> settings.CACHES
{'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
>>> 
Fisch answered 30/11, 2017 at 17:43 Comment(0)
D
2

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',
    }
}
Disarrange answered 25/7, 2022 at 19:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.