2

I have a method in python which do some processing on the input i send, and it returns a value after processing is done.

This method is taking lot of time to give the results. So, what i am doing now is for similar inputs I am caching return value using django Database caching. it worked well.

But I need the data to be stored in caching database for permanent use.

On Django website it is mentioned that "none of the Django caching backends should be used for permanent storage"(https://docs.djangoproject.com/en/1.9/topics/cache/).

I can store the data on cache database as well as regular database. But it will be performance problem.

So, what approach should i follow to do this with out performance issues.

1 Answer 1

2

As long as you do not set a timeout to your cache entries, they should not be cleared without you explicitly doing so.

Be careful that by default, caches have a 300 seconds timeout, you need to set your cache's TIMEOUT parameter to None explicitly in your settings file, example:

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.db',
        'TIMEOUT': None,
    }
}

However, it seems bad practice to me to use the database cache to store data that you want permanent (for example, clearing the whole cache is only one method call away -- cache.clear()). Why don't you create a model dedicated to storing your results ?

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

3 Comments

if i create a model dedicated for storing the result, will the speed of retrieval almost same as retrieving from cache?
It will be the same, both cases are reads from the database, the fact that it is the cache framework that performs the read does not make it faster. If you were using a different cache backend (memcached for example), then it would have a performance impact.
Thanks a lot for answer.

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.