saulshanabrook/django-dumper — pull request #19 by saulshanabrook (2013-11-11 18:50:05+00:00)
Title: Use Django Caching

The current behavior of caching only based on the path and HTTP method is not able to have different caches based on other headers.

We need to find a way to respect [vary headers](https://docs.djangoproject.com/en/dev/topics/cache/#using-vary-headers), as cache middleware does.

The first step is choosing a data format for the cache. By this I mean, how should the cache keys and values be structured? Django's cache middleware implementation is undocumented, but can be determined by their [middleware code](https://github.com/django/django/blob/master/django/middleware/cache.py).

Our current caching structure is very simple. If shown as if the Django cache was a dictionary, it would look like this:
```python
{
'dumper.cached_path.{path_hash}.{method}': ,
'dumper.cached_path.{path_hash}.{method}': ,
...
}
```

With this setup, invalidation is very easy. Just delete all possible keys from the path hash and all possible method names.

To figure out the best way to implement invalidating Django's cache we need to explain it in the same way. Note that cache keys can not be invalidated by regex's. They also can not be listed. The only way to delete a key is to use it's key name.

The old django-dumper implements it this way. The code for the old site is [here](https://github.com/saulshanabrook/django-dumper/blob/v0.1.1/dumper/middleware.py)