changeset 680:d6556513c4d3

add scope param to CacheEntry, scope=='farm' uses farmwide caching, use it for i18n
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 21 May 2006 16:54:45 +0200
parents 421b68c6533b
children 2d5883e4b82c
files MoinMoin/caching.py MoinMoin/i18n/__init__.py docs/CHANGES
diffstat 3 files changed, 15 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/caching.py	Sun May 21 13:34:42 2006 +0200
+++ b/MoinMoin/caching.py	Sun May 21 16:54:45 2006 +0200
@@ -15,7 +15,7 @@
     from MoinMoin.util import lock
     
 class CacheEntry:
-    def __init__(self, request, arena, key):
+    def __init__(self, request, arena, key, scope='page_or_wiki'):
         """ init a cache entry
             @param request: the request object
             @param arena: either a string or a page object, when we want to use
@@ -23,12 +23,15 @@
             @param key: under which key we access the cache content
         """
         self.request = request
-        if isinstance(arena, str):
-            self.arena_dir = os.path.join(request.cfg.cache_dir, arena)
+        if scope == 'page_or_wiki': # XXX split and refactor later
+            if isinstance(arena, str):
+                self.arena_dir = os.path.join(request.cfg.cache_dir, request.cfg.siteid, arena)
+                filesys.makeDirs(self.arena_dir)
+            else: # arena is in fact a page object
+                self.arena_dir = arena.getPagePath('cache', check_create=1)
+        elif scope == 'farm':
+            self.arena_dir = os.path.join(request.cfg.cache_dir, '__common__', arena)
             filesys.makeDirs(self.arena_dir)
-        else: # arena is in fact a page object
-            cache_dir = None
-            self.arena_dir = arena.getPagePath('cache', check_create=1)
         self.key = key
         if locking:
             self.lock_dir = os.path.join(self.arena_dir, '__lock__')
--- a/MoinMoin/i18n/__init__.py	Sun May 21 13:34:42 2006 +0200
+++ b/MoinMoin/i18n/__init__.py	Sun May 21 16:54:45 2006 +0200
@@ -116,9 +116,7 @@
     that requires translated strings (eg. "attachment:").
     """
     from MoinMoin import caching
-    # farm notice: for persistent servers, only the first wiki requesting some language
-    # gets its cache updated - a bit strange and redundant, but no problem.
-    cache = caching.CacheEntry(request, arena='i18n', key=lang)
+    cache = caching.CacheEntry(request, arena='i18n', key=lang, scope='farm')
     langfilename = os.path.join(os.path.dirname(__file__), '%s.py' % filename(lang))
     needsupdate = cache.needsUpdate(langfilename)
     if debug: request.log("i18n: langfilename %s needsupdate %d" % (langfilename, needsupdate))
--- a/docs/CHANGES	Sun May 21 13:34:42 2006 +0200
+++ b/docs/CHANGES	Sun May 21 16:54:45 2006 +0200
@@ -62,11 +62,16 @@
       parser.wiki -> parser.text_moin_wiki
     * Added thread_monitor. It can be activated using:
       from MoinMoin.util import thread_monitor; thread_monitor.activate_hook()
+    * Introduced scope parameter to CacheEntry() - if you specify 'farm', it
+      will cache into a common directory for all wikis in the same farm.
 
   New Features:
 
     * HTML parser (called "html") that allows you to use HTML on the page.
       Thanks to the trac team for the nice code.
+    * You can have a common cache_dir for your farm (will save a bit space
+      and cpu time as it shares some stuff).
+      You need to set "cache_dir = '/some/farm/cachedir' in your farmconfig.
 
   Bugfixes:
     * on action "info" page, "revert" link will not be displayed for empty page