0

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 2

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

this setting worked for me

Sign up to request clarification or add additional context in comments.

1 Comment

This is what I use in development on my local machine as well.
0

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.

1 Comment

even after using this also same result is coming

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.