Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
PortalTransforms.cache.Cache Class Reference

List of all members.

Public Member Functions

def __init__
def setCache
def getCache
def purgeCache

Public Attributes

 context

Private Member Functions

def _genCacheKey

Private Attributes

 _id

Detailed Description

Definition at line 6 of file cache.py.


Constructor & Destructor Documentation

def PortalTransforms.cache.Cache.__init__ (   self,
  context,
  _id = '_v_transform_cache' 
)

Definition at line 8 of file cache.py.

00008 
00009     def __init__(self, context, _id='_v_transform_cache'):
00010         self.context = context
00011         self._id =_id


Member Function Documentation

def PortalTransforms.cache.Cache._genCacheKey (   self,
  identifier,
  args 
) [private]

Definition at line 12 of file cache.py.

00012 
00013     def _genCacheKey(self, identifier, *args):
00014         key = identifier
00015         for arg in args:
00016             key = '%s_%s' % (key, arg)
00017         key = key.replace('/', '_')
00018         key = key.replace('+', '_')
00019         key = key.replace('-', '_')
00020         key = key.replace(' ', '_')
00021         return key

Here is the caller graph for this function:

def PortalTransforms.cache.Cache.getCache (   self,
  key 
)
try to get a cached value for key

return None if not present
else return a tuple (time spent in cache, value)

Definition at line 33 of file cache.py.

00033 
00034     def getCache(self, key):
00035         """try to get a cached value for key
00036 
00037         return None if not present
00038         else return a tuple (time spent in cache, value)
00039         """
00040         context = self.context
00041         key = self._genCacheKey(key)
00042         dict = getattr(context, self._id, None)
00043         if dict is None :
00044             return None
00045         try:
00046             orig_time, value = dict.get(key, None)
00047             return time() - orig_time, value
00048         except TypeError:
00049             return None
        

Here is the call graph for this function:

def PortalTransforms.cache.Cache.purgeCache (   self,
  key = None 
)
Remove cache

Definition at line 50 of file cache.py.

00050 
00051     def purgeCache(self, key=None):
00052         """Remove cache
00053         """
00054         context = self.context
00055         id = self._id
00056         if not shasattr(context, id):
00057             return
00058         if key is None:
00059             delattr(context, id)
00060         else:
00061             cache = getattr(context, id)
00062             key = self._genCacheKey(key)
00063             if cache.has_key(key):
00064                 del cache[key]

Here is the call graph for this function:

def PortalTransforms.cache.Cache.setCache (   self,
  key,
  value 
)
cache a value indexed by key

Definition at line 22 of file cache.py.

00022 
00023     def setCache(self, key, value):
00024         """cache a value indexed by key"""
00025         if not value.isCacheable():
00026             return
00027         context = self.context
00028         key = self._genCacheKey(key)
00029         if getattr(aq_base(context), self._id, None) is None:
00030             setattr(context, self._id, {})
00031         getattr(context, self._id)[key] = (time(), value)
00032         return key

Here is the call graph for this function:


Member Data Documentation

Definition at line 10 of file cache.py.

Definition at line 9 of file cache.py.


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