I am using the view cache for Django 1.10. But I am having problems clearing the cache.
@cache_page(60 * 30, cache="container_table")
def container_table(request, dataset):
# determine container_list by a query to the database
return render(request, 'container_table.html',{"container_list":container_list})
Then container_table.html creates a table involving container_list and each row has an element of container_list
along with a little checkbox
. When the checkbox
is checked
, I want the cache to clear. So essentially when the checkbox is checked, an ajax call is made to a view that does caches["container_table"].clear()
.
From the django docs, this should clear ALL keys in that cache, but it is not working because when I refresh the page for container_table.html it is still using a cache. Am I misunderstanding the usage of caches["container_table"].clear()
?
I thought it would clear everything!
The cache_page decorator inserts the result into the cache AFTER the view code has run. So although I cleared the cache partway through executing the view, the cache_page decorator will insert something into the cache right after, and any code looking at the cache afterward will see at least that one cached value in there.
Instead of using view caching, I used template caching, and it worked perfectly. Plus, it is considerably easier to pinpoint the key used for the template fragment by using make_template_fragment_key. Thus, I do not have to delete all the keys in the cache, just the specific one used for that fragment