pycocoa.utils.Cache2

Package pycocoa :: Module utils :: Class Cache2 |
[frames] | no frames]

# Class Cache2

    object --+
             |
          dict --+
                 |
                Cache2

Two-level cache implemented by two `dict`s, a primary level-1 `dict` and a secondary level-2 `dict`.

Newly created key-value pairs are entered into the secondary `dict`. Repeatedly gotten key-value items are elevated from the secondadry to the primary `dict`.

The secondary `dict` can optionally be limited in size to avoid excessive growth.

Instance Methods
    new empty dictionary
__init__(self, limit2=None) New Cache2, optionally limited in size. |
True if D has a key k, else False |
__contains__(self, key) |
__getitem__(self, key) x[y] |
__setitem__(self, key, value) x[i]=y |
D[k] if k in D, else d |
get(self, key, default=None) Return the specified item's value. |
v, remove specified key and return the corresponding value |
pop(self, key, *default) Remove the specified item. |
(k, v), remove and return some (key, value) pair as a |
popitem(self) Remove the item most recently elevated into the primary level-1 `dict`. |
None |
update(self, *other, **kwds) Update this cache with one or more additional items. |
Inherited from `dict`: `__cmp__`, `__delitem__`, `__eq__`, `__ge__`, `__getattribute__`, `__gt__`, `__iter__`, `__le__`, `__len__`, `__lt__`, `__ne__`, `__new__`, `__repr__`, `__sizeof__`, `clear`, `copy`, `fromkeys`, `has_key`, `items`, `iteritems`, `iterkeys`, `itervalues`, `keys`, `setdefault`, `values`, `viewitems`, `viewkeys`, `viewvalues` Inherited from `object`: `__delattr__`, `__format__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__str__`, `__subclasshook__`

Class Variables
Inherited from `dict`: `__hash__`

Properties
| dict2 Get the secondary level-2 `dict`.
| limit2 Get the secondary level-2 `dict` size limit (`int` or `None`).
Inherited from `object`: `__class__`

Method Details

### __init__(self, limit2=None) (Constructor) |
New Cache2, optionally limited in size. Parameters: `limit2` - Size limit for the secondary level-2 `dict` (`int` or `None`). Returns:
    new empty dictionary
Overrides: object.__init__

### __contains__(self, key) (In operator) |
Returns: True if D has a key k, else False Overrides: dict.__contains__ (inherited documentation)

### __getitem__(self, key) (Indexing operator) |
x[y] Overrides: dict.__getitem__ (inherited documentation)

### __setitem__(self, key, value) (Index assignment operator) |
x[i]=y Overrides: dict.__setitem__ (inherited documentation)

### get(self, key, default=None) |
Return the specified item's value. Parameters: `key` - The item's key (`any`). `default` - Default value for missing item (`any`). Returns: D[k] if k in D, else d `Cache2`[key] if key in `Cache2` else default or `None` if no default specified. Overrides: dict.get

### pop(self, key, *default) |
Remove the specified item. Parameters: `key` - The item's key (`any`). `default` - Value for missing item (`any`). Returns: v, remove specified key and return the corresponding value `Cache2`[key] if key in `Cache2` else default, provided default was specified. Raises: `KeyError` - No such item key and no default given. Overrides: dict.pop Note: If key is not in the primary level-1 `dict`, the secondary level-2 `dict` is checked.

### popitem(self) |
Remove the item most recently elevated into the primary level-1 `dict`. Returns: (k, v), remove and return some (key, value) pair as a The removed item as 2-Tuple (key, value). Raises: `KeyError` - The secondary level-2 `dict` is empty. Overrides: dict.popitem Note: Use `Cache2.dict2.popitem()` to remove the most recently entered item to the secondary level-2 `dict`.

### update(self, *other, **kwds) |
Update this cache with one or more additional items. Parameters: `other` - Items specified as an iterable of 2-tuples `(key, value)` or as a `dict`. `kwds` - Items given as `key=value` pairs, with priority over `other`. Returns: None Overrides: dict.update

Property Details

### dict2 Get the secondary level-2 `dict`. Get Method: dict2(self) - Get the secondary level-2 `dict`. Set Method: Read_Only(self, ignored) - Throws an `AttributeError`, always.

### limit2 Get the secondary level-2 `dict` size limit (`int` or `None`). Get Method: limit2(self) - Get the secondary level-2 `dict` size limit (`int` or `None`). Set Method: Read_Only(self, ignored) - Throws an `AttributeError`, always.