Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
MoinMoin.Page.ItemCache Class Reference

List of all members.

Public Member Functions

def __init__
def putItem
def getItem
def refresh

Public Attributes

 name
 cache
 log_pos
 requests
 hits
 loglevel

Detailed Description

Cache some page item related data, as meta data or pagelist

    We only cache this to RAM in request.cfg (this is the only kind of
    server object we have), because it might be too big for pickling it
    in and out.

Definition at line 51 of file Page.py.


Constructor & Destructor Documentation

def MoinMoin.Page.ItemCache.__init__ (   self,
  name 
)
Initialize ItemCache object.
    @param name: name of the object, used for display in logging and
         influences behaviour of refresh().

Definition at line 58 of file Page.py.

00058 
00059     def __init__(self, name):
00060         """ Initialize ItemCache object.
00061             @param name: name of the object, used for display in logging and
00062                          influences behaviour of refresh().
00063         """
00064         self.name = name
00065         self.cache = {}
00066         self.log_pos = None # TODO: initialize this to EOF pos of log
00067                             # to avoid reading in the whole log on first request
00068         self.requests = 0
00069         self.hits = 0
00070         self.loglevel = logging.NOTSET


Member Function Documentation

def MoinMoin.Page.ItemCache.getItem (   self,
  request,
  name,
  key 
)
Returns some item stored for item name under key.
    @param request: the request object
    @param name: name of the item (page), unicode
    @param key: used as secondary access key after name
    @return: the data or None, if there is no such name or key.

Definition at line 81 of file Page.py.

00081 
00082     def getItem(self, request, name, key):
00083         """ Returns some item stored for item name under key.
00084             @param request: the request object
00085             @param name: name of the item (page), unicode
00086             @param key: used as secondary access key after name
00087             @return: the data or None, if there is no such name or key.
00088         """
00089         self.refresh(request)
00090         try:
00091             data = self.cache[name][key]
00092             self.hits += 1
00093             hit_str = 'hit'
00094         except KeyError:
00095             data = None
00096             hit_str = 'miss'
00097         self.requests += 1
00098         logging.log(self.loglevel, "%s cache %s (h/r %2.1f%%) for %r %r" % (
00099             self.name,
00100             hit_str,
00101             float(self.hits * 100) / self.requests,
00102             name,
00103             key,
00104         ))
00105         return data

Here is the call graph for this function:

def MoinMoin.Page.ItemCache.putItem (   self,
  request,
  name,
  key,
  data 
)
Remembers some data for item name under a key.
    @param request: currently unused
    @param name: name of the item (page), unicode
    @param key: used as secondary access key after name
    @param data: the data item that should be remembered

Definition at line 71 of file Page.py.

00071 
00072     def putItem(self, request, name, key, data):
00073         """ Remembers some data for item name under a key.
00074             @param request: currently unused
00075             @param name: name of the item (page), unicode
00076             @param key: used as secondary access key after name
00077             @param data: the data item that should be remembered
00078         """
00079         d = self.cache.setdefault(name, {})
00080         d[key] = data

def MoinMoin.Page.ItemCache.refresh (   self,
  request 
)
Refresh the cache - if anything has changed in the wiki, we see it
    in the edit-log and either delete cached data for the changed items
    (for 'meta') or the complete cache ('pagelists').
    @param request: the request object

Definition at line 106 of file Page.py.

00106 
00107     def refresh(self, request):
00108         """ Refresh the cache - if anything has changed in the wiki, we see it
00109             in the edit-log and either delete cached data for the changed items
00110             (for 'meta') or the complete cache ('pagelists').
00111             @param request: the request object
00112         """
00113         from MoinMoin.logfile import editlog
00114         elog = editlog.EditLog(request)
00115         old_pos = self.log_pos
00116         new_pos, items = elog.news(old_pos)
00117         if items:
00118             if self.name == 'meta':
00119                 for item in items:
00120                     logging.log(self.loglevel, "cache: removing %r" % item)
00121                     try:
00122                         del self.cache[item]
00123                     except:
00124                         pass
00125             elif self.name == 'pagelists':
00126                 logging.log(self.loglevel, "cache: clearing pagelist cache")
00127                 self.cache = {}
00128         self.log_pos = new_pos # important to do this at the end -
00129                                # avoids threading race conditions
00130 

Here is the caller graph for this function:


Member Data Documentation

Definition at line 64 of file Page.py.

Definition at line 68 of file Page.py.

Definition at line 65 of file Page.py.

Definition at line 69 of file Page.py.

Definition at line 63 of file Page.py.

Definition at line 67 of file Page.py.


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