Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes
plone.memoize.volatile.CleanupDict Class Reference

List of all members.

Public Member Functions

def __init__
def __getitem__
def __setitem__

Public Attributes

 cleanup_period

Static Public Attributes

int cleanup_period = 60

Private Member Functions

def _cleanup

Private Attributes

 _last_access

Detailed Description

A dict that automatically cleans up items that haven't been
accessed in a given timespan on *set*.

This implementation is a bit naive, since it's not associated with
any policy that the user can configure, and it doesn't provide
statistics like RAMCache, but at least it helps make sure our
volatile attribute doesn't grow stale entries indefinitely.

  >>> d = CleanupDict()
  >>> d['spam'] = 'bar'
  >>> d['spam']
  'bar'

  >>> d = CleanupDict(0)
  >>> d['spam'] = 'bar'
  >>> d['spam'] # doctest: +ELLIPSIS
  Traceback (most recent call last):
  ...
  KeyError: 'spam'

Definition at line 201 of file volatile.py.


Constructor & Destructor Documentation

def plone.memoize.volatile.CleanupDict.__init__ (   self,
  cleanup_period = None 
)

Definition at line 224 of file volatile.py.

00224 
00225     def __init__(self, cleanup_period=None):
00226         super(CleanupDict, self).__init__()
00227         self._last_access = {}
00228         if cleanup_period is not None:
00229             self.cleanup_period = cleanup_period

Here is the caller graph for this function:


Member Function Documentation

Definition at line 230 of file volatile.py.

00230 
00231     def __getitem__(self, key):
00232         value = super(CleanupDict, self).__getitem__(key)
00233         self._last_access[key] = time.time()
00234         return value

Here is the caller graph for this function:

def plone.memoize.volatile.CleanupDict.__setitem__ (   self,
  key,
  value 
)

Definition at line 235 of file volatile.py.

00235 
00236     def __setitem__(self, key, value):
00237         super(CleanupDict, self).__setitem__(key, value)
00238         self._last_access[key] = time.time()
00239         self._cleanup()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 240 of file volatile.py.

00240 
00241     def _cleanup(self):
00242         now = time.time()
00243         okay = now - self.cleanup_period
00244         for key, timestamp in self._last_access.items():
00245             if timestamp < okay:
00246                 del self._last_access[key]
                super(CleanupDict, self).__delitem__(key)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 226 of file volatile.py.

Definition at line 222 of file volatile.py.

Definition at line 228 of file volatile.py.


The documentation for this class was generated from the following file: