S
S
sandrosklyarov2019-05-07 12:33:22
Django
sandrosklyarov, 2019-05-07 12:33:22

Django - Does the cache timeout count after the last hit or after it's been set?

from django.core.cache import caches, DEFAULT_CACHE_ALIAS

cache = caches[DEFAULT_CACHE_ALIAS]
cache.set(cache_key, data, timeout)

The question is - I set a timeout value in the cache, let's say 300 seconds. Will the cache be reset 300 seconds after it was set, or 300 seconds after it was last accessed?
data = cache.get(cache_key)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vadim Shatalov, 2019-05-07
@netpastor

Time to live after installation
https://docs.djangoproject.com/en/dev/topics/cache...

The timeout argument is optional and defaults to the timeout argument of the appropriate backend in the CACHES setting (explained above). It's the number of seconds the value should be stored in the cache.

R
Roman Kitaev, 2019-05-07
@deliro

Of course, 300 seconds after installation.
After the last appeal - some kind of nonsense. Are you saying that if I go to the cache every 299 seconds, I can keep the value of the key indefinitely? But what about invalidation, cache fading? And how do you control such a cache?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question