Closed
Description
cache.clear() raises NotImplementedError during request/view processing between debug toolbar middleware request processing and debug toolbar middleware response processing.
This is a copy of my message in closed issue #570:
It took me all of 10 minutes to find out why this was happening in my project, inside a view function:
- the cache panel replaces the default cache (and the get_cache) function during the request middleware processing with CacheStatTracker/a function returning CacheStatTracker
- processing continues until the actual view function is called
- cache.clear() is called inside the view function, on CacheStatTracker
- CacheStatTracker has no clear() method, but has inherited the clear() method from BaseCache
- clear() is called on BaseCache
- BaseCache raises NotImplementedError
You won't find this occurring outside a view function, because on the way back out, the processing passes through the debug toolbar middleware again, this time calling disable_instrumentation on the cache panel, which replaces the cache/get_cache with the original values again.