core/cachecore — pull request #3 by turicas (2012-07-18 07:16:10+00:00)
Title: Mapping-like interface

With these little changes we can use any `BaseCache` child classes as a Python `dict` (using `collections.MutableMapping`), with some little limitations compared to `dict`:

- `iteritems()`, `keys()`, `values()` and `len()` and other methods related to getting all keys/values will not work unless you implement `__iter__` and `__len__` in the child class.
- If my cache doesn't have the key `test` and I execute `my_cache['test']` it **will not** raise `KeyError` like in a `dict`; it'll return `None` (as the current `BaseCache.get` API).

This modification is very handy in cases when we are using `dict`s to store and then need to persist or cache them in some way, since only the line that creates the `dict` needs to be replaced.