Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache should have dictionary-like syntactic sugar #1

Open
maniksurtani opened this issue Apr 19, 2011 · 0 comments
Open

Cache should have dictionary-like syntactic sugar #1

maniksurtani opened this issue Apr 19, 2011 · 0 comments
Assignees

Comments

@maniksurtani
Copy link
Member

The Cache class uses Java Map-style put(), get(), remove() and contains(). Which is fine, but we should also offer Python-style syntactic sugar, so that we can do:

cache['key'] = 'value'
print cache['key']
if 'key' in cache:
  print 'Key exists!'
for e in cache:
  print e

etc. Have a look at the implementation of a Python map for more details, or one of the many custom map-like classes available for Python.

This is usually implemented by defining internal methods, such as:

def __getitem__(self, key):
  return self.get(key)

def __setitem__(self, key, value):
  self.put(key, value)

etc.

@ghost ghost assigned galderz Apr 19, 2011
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

No branches or pull requests

2 participants