Skip to content

Conversation

turicas
Copy link

@turicas turicas commented Jul 18, 2012

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 dicts 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant