key-based invalidation of template fragment does not work

Hi there,

I’m currently trying to speed up the rendering of a template by caching the relevant section with:

{% load cache %}

{% cache None repotree %}

<expensive operation>

{% endcache %}

So far, everything works as expected: when the site gets loaded for the first time it takes ~600 ms and only ~5 ms for every access after that.

When the data in the database gets updated, I would like to invalidate the cache. In my code I have:

from django.core.cache import cache
from django.core.cache.utils import make_template_fragment_key

key = make_template_fragment_key('repotree')
cache.delete(key)

cache.delete(key) returns True but when I access the page, it still contains the old data.

When I delete the entire cache with cache.clear() new data is displayed afterwards. However, I would prefer to only invalidate the specific key.

Caching is configured as follows:

CACHES = {                      
    'default': {                                                      
        'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
        'LOCATION': '/tmp/django_cache',            
    }                                           
}

My application runs in a docker container.

I’ve tried to run django-debug-toolbar but couldn’t get it to work so far.

Any help would be greatly appreciated.

Lukas