I'm using redis for caching in a django app. I'm also using Django Rest Framework, and here is my problem.
I'm using the cache system like this:
from django.views.decorators.cache import cache_page
urlpatterns = [
...
url(r'^some_url/$', cache_page(CACHE_TTL)(SomeView.as_view())
...
]
Here, SomeView
is a class that inherits from APIView.
Now imagine we make a request to this url and we receive a json object containing one instance of whatever this url returns.
Then we proceed to delete (using django's admin interface) that object, and make the request again. The expected result is an empty json object, but what I'm receiving is the same object unchanged, the same happens if a new object is added, the response still only one object.
After some time (the TTL of the request in cache) the result is correct.
So, how can I tell django that a cache entry it is no valid any more?