miracle2k/webassets — pull request #314 by satiani (2014-05-10 16:05:09+00:00)
Title: Allow filters to customize cache keys + change CSSRewrite cache key

Lets say you have a file called ```static/css/common.css```, that looks like this:

```
.icon {
background: url(../img/icon.png) no-repeat;
}
```

and you're using common.css in two generated files (bundles), one which gets output to ```gen/static/css/first.css```, and one to ```gen/static/css/deep/deeper/second.css```. When you do asset build, the first bundle gets processed, and it rewrites the url in common.css so that it looks like:

```
.icon {
background: url(../../img/icon.png) no-repeat;
}
```

Then it caches the output of common.css rewrite according to a cache key:

```
key = ("hunk", hunk, tuple(filters), type)
```

which, in this case, basically boils down to the contents of the input file (original common.css).

When it is time to process the second.css file, it checks the cache first, building the cache key using the contents of the original common.css, which did not change. Of course, it finds the file cached from the run for the first bundle, and then uses that one, without passing it through CSSRewrite again. This is not the desired behavior in this case, since second.css is two levels deeper in the directory heirarchy, the URLs have to be rewritten again, i.e. the common.css file should look like:

```
.icon {
background: url(../../../../img/icon.png) no-repeat;
}
```

By including the base directory of the output file of a bundle as part of the cache key whenever CSSRewrite is involved, we make sure we get the appropriate behavior.

This patch consists of two commits, the first one allows individual filters to specify additional cache keys, the second part utliizes the first commit to allow CSSRewrite to include the directory name in the cache keys.