Package logilab :: Package common :: Module cache :: Class Cache

[frames] | no frames]

# Class Cache

source code

    object --+
             |
          dict --+
                 |
                Cache

    A dictionary like cache.

    inv:
        len(self._usage) <= self.size
        len(self.data) <= self.size

Instance Methods

    new empty dictionary

__init__(self, size=100) Warning : Cache.__init__() != dict.__init__(). | source code

(k, v), remove and return some (key, value) pair as a

popitem(self) 2-tuple; but raise KeyError if D is empty. | source code

D.get(k,d), also set D[k]=d if k not in D

setdefault(self, key, default=None) | source code

None

update(self, other) Update D from dict/iterable E and F. | source code

Inherited from `dict`: `__cmp__`, `__contains__`, `__eq__`, `__ge__`, `__getattribute__`, `__gt__`, `__iter__`, `__le__`, `__len__`, `__lt__`, `__ne__`, `__new__`, `__repr__`, `__sizeof__`, `copy`, `fromkeys`, `get`, `has_key`, `items`, `iteritems`, `iterkeys`, `itervalues`, `keys`, `values`, `viewitems`, `viewkeys`, `viewvalues`

Inherited from `object`: `__delattr__`, `__format__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__str__`, `__subclasshook__`

Class Variables
| __getitem__ = `locked(_acquire, _release)(__getitem__)` x[y]
| __setitem__ = `locked(_acquire, _release)(__setitem__)` x[i]=y
| __delitem__ = `locked(_acquire, _release)(__delitem__)` del x[y]
| clear = `locked(_acquire, _release)(clear)` Remove all items from D.
| pop = `locked(_acquire, _release)(pop)` If key is not found, d is returned if given, otherwise KeyError is raised
Inherited from `dict`: `__hash__`

Properties
Inherited from `object`: `__class__`

Method Details

### __init__(self, size=100)
(Constructor)

source code

    Warning : Cache.__init__() != dict.__init__().
    Constructor does not take any arguments beside size.

Returns:

    new empty dictionary

Overrides: object.__init__

### popitem(self)

source code

2-tuple; but raise KeyError if D is empty.

Returns: (k, v), remove and return some (key, value) pair as a
Overrides: dict.popitem
  (inherited documentation)

### setdefault(self, key, default=None)

source code

Returns: D.get(k,d), also set D[k]=d if k not in D
Overrides: dict.setdefault
  (inherited documentation)

### update(self, other)

source code

Update D from dict/iterable E and F. If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

Returns: None
Overrides: dict.update
  (inherited documentation)