D
D
Denis Karimov2017-08-04 17:42:10
Django
Denis Karimov, 2017-08-04 17:42:10

Why doesn't file caching work correctly in Django?

I think many have come across, but perhaps not everyone noticed. I have this problem already on the third project.
Generally. I set up file caching in a very trite way, only in settings:

MIDDLEWARE = [
    'django.middleware.cache.UpdateCacheMiddleware',
    'django.middleware.gzip.GZipMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.cache.FetchFromCacheMiddleware',
]

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
        'LOCATION': os.path.join(BASE_DIR, 'cache'),
    'TIMEOUT': 300,
        'OPTIONS': {
            'MAX_ENTRIES': 1000
        }
    }
}

And here is the most interesting. We go to any page, it is cached. Then we change something in the system and start updating the page on the frontend. On 2-3 updates, a modified version appears (although the storage time has not yet passed), and after that, if you update the page, the page will dance between the old and new versions. This happens until the cache time of the first version has passed.
Is this a bug, a bug or a feature for very annoying visitors?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ovdienko, 2017-08-04
@trixden

Depending on what you cached.
I had such tricks when on site cache was enabled.
I sawed it out and made it in pieces in the template and in the views

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question