skip to Main Content

i want to cache in django so I am using low level API caching but even after adding it shows none

>>> from django.core.cache import cache
>>> cache.set('my_key', 'hello, world!')
>>> cache.get('my_key')
>>> print(cache.get('my_key'))
None
>>>

in my settings.py

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211',
    }
}

even when i use cache.add('my_key', 'hello, world!', 30) it return false

2

Answers


  1. Chosen as BEST ANSWER
    CACHES = {
        'default': {
            'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
        }
    }
    

    this setting worked for me


  2. You can try to set timeout:

    CACHES = {
        'default': {
            'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
            'LOCATION': 'exchange_rate_cache',
            'TIMEOUT': 604800  # 7 days
        }
    }
    

    You can set the timeout to None to remove it completely.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search