changeset 682:1314fdb74689

refactor CacheEntry usage to use scope param
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 21 May 2006 18:14:30 +0200
parents 2d5883e4b82c
children a2beb43407ea
files MoinMoin/Page.py MoinMoin/PageEditor.py MoinMoin/_tests/test_PageEditor.py MoinMoin/_tests/test_user.py MoinMoin/action/__init__.py MoinMoin/macro/PageHits.py MoinMoin/packages.py MoinMoin/parser/text_xslt.py MoinMoin/request/__init__.py MoinMoin/stats/hitcounts.py MoinMoin/stats/useragents.py MoinMoin/theme/classic.py MoinMoin/user.py MoinMoin/util/antispam.py MoinMoin/wikidicts.py
diffstat 15 files changed, 23 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Sun May 21 18:01:23 2006 +0200
+++ b/MoinMoin/Page.py	Sun May 21 18:14:30 2006 +0200
@@ -1292,7 +1292,7 @@
 
         # cache the pagelinks
         if do_cache and self.default_formatter and page_exists:
-            cache = caching.CacheEntry(request, self, 'pagelinks')
+            cache = caching.CacheEntry(request, self, 'pagelinks', scope='item')
             if cache.needsUpdate(self._text_filename()):
                 links = self.formatter.pagelinks
                 cache.update('\n'.join(links) + '\n', True)
@@ -1388,7 +1388,7 @@
 
     def loadCache(self, request):
         """ Return page content cache or raises 'CacheNeedsUpdate' """
-        cache = caching.CacheEntry(request, self, self.getFormatterName())
+        cache = caching.CacheEntry(request, self, self.getFormatterName(), scope='item')
         attachmentsPath = self.getPagePath('attachments', check_create=0)
         if cache.needsUpdate(self._text_filename(), attachmentsPath):
             raise 'CacheNeedsUpdate'
@@ -1421,7 +1421,7 @@
         src = formatter.assemble_code(text)
         code = compile(src.encode(config.charset),
                        self.page_name.encode(config.charset), 'exec')
-        cache = caching.CacheEntry(request, self, self.getFormatterName())
+        cache = caching.CacheEntry(request, self, self.getFormatterName(), scope='item')
         cache.update(marshal.dumps(code))
         self.cache_mtime = cache.mtime()
         return code
@@ -1535,7 +1535,7 @@
         """
         if not self.exists():
             return []
-        cache = caching.CacheEntry(request, self, 'pagelinks')
+        cache = caching.CacheEntry(request, self, 'pagelinks', scope='item')
         if cache.needsUpdate(self._text_filename()):
             links = self.parsePageLinks(request)
             cache.update('\n'.join(links) + '\n', True)
--- a/MoinMoin/PageEditor.py	Sun May 21 18:01:23 2006 +0200
+++ b/MoinMoin/PageEditor.py	Sun May 21 18:14:30 2006 +0200
@@ -533,7 +533,7 @@
         # delete pagelinks
         arena = self
         key = 'pagelinks'
-        cache = caching.CacheEntry(self.request, arena, key)
+        cache = caching.CacheEntry(self.request, arena, key, scope='item')
         cache.remove()
 
         # forget in-memory page text
@@ -546,7 +546,7 @@
         for formatter_name in self.cfg.caching_formats:
             arena = self
             key = formatter_name
-            cache = caching.CacheEntry(self.request, arena, key)
+            cache = caching.CacheEntry(self.request, arena, key, scope='item')
             cache.remove()
         return success, msg
 
--- a/MoinMoin/_tests/test_PageEditor.py	Sun May 21 18:01:23 2006 +0200
+++ b/MoinMoin/_tests/test_PageEditor.py	Sun May 21 18:14:30 2006 +0200
@@ -151,7 +151,7 @@
     def deleteCaches(self):
         """ Force the wiki to scan the test page into the dicts """
         from MoinMoin import caching
-        caching.CacheEntry(self.request, 'wikidicts', 'dicts_groups').remove()
+        caching.CacheEntry(self.request, 'wikidicts', 'dicts_groups', scope='wiki').remove()
         if hasattr(self.request, 'dicts'):
             del self.request.dicts
         if hasattr(self.request.cfg, 'DICTS_DATA'):
--- a/MoinMoin/_tests/test_user.py	Sun May 21 18:01:23 2006 +0200
+++ b/MoinMoin/_tests/test_user.py	Sun May 21 18:14:30 2006 +0200
@@ -74,7 +74,7 @@
         self.request.user = self.saved_user
                 
         # Remove user name to id cache, or next test will fail
-        caching.CacheEntry(self.request, 'user', 'name2id').remove()
+        caching.CacheEntry(self.request, 'user', 'name2id', scope='wiki').remove()
         del self.request.cfg._name2id
         
         # Prevent user list caching - we create and delete users too
--- a/MoinMoin/action/__init__.py	Sun May 21 18:01:23 2006 +0200
+++ b/MoinMoin/action/__init__.py	Sun May 21 18:14:30 2006 +0200
@@ -275,8 +275,8 @@
 
     # Remove cache entry (if exists), and send the page
     from MoinMoin import caching
-    caching.CacheEntry(request, arena, key).remove()
-    caching.CacheEntry(request, arena, "pagelinks").remove()
+    caching.CacheEntry(request, arena, key, scope='item').remove()
+    caching.CacheEntry(request, arena, "pagelinks", scope='item').remove()
     do_show(pagename, request)
 
 def do_revert(pagename, request):
--- a/MoinMoin/macro/PageHits.py	Sun May 21 18:01:23 2006 +0200
+++ b/MoinMoin/macro/PageHits.py	Sun May 21 18:14:30 2006 +0200
@@ -25,8 +25,7 @@
     def __init__(self, macro, args):
         self.macro = macro
         self.request = macro.request
-        self.cache = cache = caching.CacheEntry(self.request, 'charts',
-                                                'pagehits')
+        self.cache = cache = caching.CacheEntry(self.request, 'charts', 'pagehits', scope='wiki')
 
     def execute(self):
         """ Execute the macro and return output """
--- a/MoinMoin/packages.py	Sun May 21 18:01:23 2006 +0200
+++ b/MoinMoin/packages.py	Sun May 21 18:14:30 2006 +0200
@@ -272,7 +272,7 @@
         except AttributeError:
             pass
         self.request.pages = {}
-        caching.CacheEntry(self.request, 'wikidicts', 'dicts_groups').remove()
+        caching.CacheEntry(self.request, 'wikidicts', 'dicts_groups', scope='wiki').remove()
         page.clean_acl_cache()
 
     def runScript(self, commands):
--- a/MoinMoin/parser/text_xslt.py	Sun May 21 18:01:23 2006 +0200
+++ b/MoinMoin/parser/text_xslt.py	Sun May 21 18:14:30 2006 +0200
@@ -115,7 +115,7 @@
                 self.request.write(text.decode(config.charset))
             else:
                 self.request.write(result)
-                cache = caching.CacheEntry(self.request, formatter.page, self.key)
+                cache = caching.CacheEntry(self.request, formatter.page, self.key, scope='item')
                 cache.update(result)
 
     def _resolve_page(self, uri, base):
--- a/MoinMoin/request/__init__.py	Sun May 21 18:01:23 2006 +0200
+++ b/MoinMoin/request/__init__.py	Sun May 21 18:14:30 2006 +0200
@@ -191,7 +191,8 @@
         surge_detected = False
         
         try:
-            cache = caching.CacheEntry(self, 'surgeprotect', 'surge-log')
+            # if we have common farm users, we could also use scope='farm':
+            cache = caching.CacheEntry(self, 'surgeprotect', 'surge-log', scope='wiki')
             if cache.exists():
                 data = cache.content()
                 data = data.split("\n")
--- a/MoinMoin/stats/hitcounts.py	Sun May 21 18:01:23 2006 +0200
+++ b/MoinMoin/stats/hitcounts.py	Sun May 21 18:14:30 2006 +0200
@@ -56,7 +56,7 @@
     
     cache_days, cache_views, cache_edits = [], [], []
     cache_date = 0
-    cache = caching.CacheEntry(request, arena, 'hitcounts')
+    cache = caching.CacheEntry(request, arena, 'hitcounts', scope='wiki')
     if cache.exists():
         try:
             cache_date, cache_days, cache_views, cache_edits = eval(cache.content())
--- a/MoinMoin/stats/useragents.py	Sun May 21 18:01:23 2006 +0200
+++ b/MoinMoin/stats/useragents.py	Sun May 21 18:14:30 2006 +0200
@@ -46,7 +46,7 @@
 
 def get_data(request):
     # get results from cache
-    cache = caching.CacheEntry(request, 'charts', 'useragents')
+    cache = caching.CacheEntry(request, 'charts', 'useragents', scope='wiki')
     cache_date, data = 0, {}
     if cache.exists():
         try:
--- a/MoinMoin/theme/classic.py	Sun May 21 18:01:23 2006 +0200
+++ b/MoinMoin/theme/classic.py	Sun May 21 18:14:30 2006 +0200
@@ -202,7 +202,7 @@
         params = '%s?action=%s' % (d['page_name'], 'refresh')
         link = wikiutil.link_tag(request, params, title)
         
-        cache = caching.CacheEntry(request, page, page.getFormatterName())
+        cache = caching.CacheEntry(request, page, page.getFormatterName(), scope='item')
         date = request.user.getFormattedDateTime(cache.mtime())
         deletecache = u'<p>%s %s</p>' % (link, _('(cached %s)') % date)
 
--- a/MoinMoin/user.py	Sun May 21 18:01:23 2006 +0200
+++ b/MoinMoin/user.py	Sun May 21 18:14:30 2006 +0200
@@ -50,7 +50,7 @@
     except AttributeError:
         arena = 'user'
         key = 'name2id'
-        cache = caching.CacheEntry(request, arena, key)
+        cache = caching.CacheEntry(request, arena, key, scope='wiki')
         try:
             _name2id = pickle.loads(cache.content())
         except (pickle.UnpicklingError, IOError, EOFError, ValueError):
@@ -64,7 +64,7 @@
         cfg._name2id = _name2id
         arena = 'user'
         key = 'name2id'
-        cache = caching.CacheEntry(request, arena, key)
+        cache = caching.CacheEntry(request, arena, key, scope='wiki')
         cache.update(pickle.dumps(_name2id, PICKLE_PROTOCOL))
         id = _name2id.get(searchName, None)
     return id
--- a/MoinMoin/util/antispam.py	Sun May 21 18:01:23 2006 +0200
+++ b/MoinMoin/util/antispam.py	Sun May 21 18:14:30 2006 +0200
@@ -78,7 +78,7 @@
     if do_update:
         tooold = time.time() - 3600
         mymtime = wikiutil.version2timestamp(p.mtime_usecs())
-        failure = caching.CacheEntry(request, "antispam", "failure")
+        failure = caching.CacheEntry(request, "antispam", "failure", scope='wiki')
         fail_time = failure.mtime() # only update if no failure in last hour
         if (mymtime < tooold) and (fail_time < tooold):
             dprint("%d *BadContent too old, have to check for an update..." % tooold)
--- a/MoinMoin/wikidicts.py	Sun May 21 18:01:23 2006 +0200
+++ b/MoinMoin/wikidicts.py	Sun May 21 18:14:30 2006 +0200
@@ -318,7 +318,7 @@
             self.__dict__.update(self.cfg.DICTS_DATA)
         except AttributeError:
             try:
-                cache = caching.CacheEntry(request, arena, key)
+                cache = caching.CacheEntry(request, arena, key, scope='wiki')
                 data = pickle.loads(cache.content())
                 self.__dict__.update(data)
                 
@@ -404,7 +404,7 @@
             for name in self.groupdict:
                 self.dictdict[name].expandgroups(self)
 
-            cache = caching.CacheEntry(request, arena, key)
+            cache = caching.CacheEntry(request, arena, key, scope='wiki')
             cache.update(pickle.dumps(data, PICKLE_PROTOCOL))
             
         # remember it (persistent environments)