1.1 --- a/MoinSupport.py Tue Jan 21 18:26:01 2014 +0100
1.2 +++ b/MoinSupport.py Sat Jan 25 18:39:32 2014 +0100
1.3 @@ -4,7 +4,7 @@
1.4
1.5 @copyright: 2008, 2009, 2010, 2011, 2012, 2013, 2014 by Paul Boddie <paul@boddie.org.uk>
1.6 @copyright: 2000-2004 Juergen Hermann <jh@web.de>
1.7 - 2004 by Florian Festi
1.8 + 2004,2006 by Florian Festi
1.9 2006 by Mikko Virkkil
1.10 2005-2008 MoinMoin:ThomasWaldmann
1.11 2007 MoinMoin:ReimarBauer
1.12 @@ -15,7 +15,8 @@
1.13 from DateSupport import *
1.14 from MoinMoin.parser import text_moin_wiki
1.15 from MoinMoin.Page import Page
1.16 -from MoinMoin import config, search, wikiutil
1.17 +from MoinMoin.support.python_compatibility import hash_new
1.18 +from MoinMoin import caching, config, search, wikiutil
1.19 from shlex import shlex
1.20 import re
1.21 import time
1.22 @@ -810,6 +811,64 @@
1.23
1.24 return {"timestamp" : DateTime(time.gmtime(mtime)[:6] + ("UTC",)), "comment" : comment}
1.25
1.26 +# Page caching functions.
1.27 +
1.28 +def getPageCacheKey(page, request):
1.29 +
1.30 + """
1.31 + Return a cache key for the given 'page' using information in the 'request'.
1.32 + """
1.33 +
1.34 + if hasattr(page, "getCacheKey"):
1.35 + return page.getCacheKey(request)
1.36 +
1.37 + key = getPageFormatterName(page, request)
1.38 + if request.args:
1.39 + args = request.args.items()
1.40 + args.sort()
1.41 + key_args = []
1.42 + for k, v in args:
1.43 + key_args.append("%s=%s" % (k, wikiutil.url_quote(v)))
1.44 + arg_str = "&".join(key_args)
1.45 + key = "%s:%s" % (key, hash_new('sha1', arg_str).hexdigest())
1.46 + return key
1.47 +
1.48 +def enforcePageCacheLimit(page, request):
1.49 +
1.50 + """
1.51 + Prevent too many cache entries being stored for the given 'page', using the
1.52 + 'request' to obtain cache items and configuration details.
1.53 + """
1.54 +
1.55 + if hasattr(page, "enforceCacheLimit"):
1.56 + page.enforceCacheLimit(request)
1.57 +
1.58 + keys = caching.get_cache_list(request, page, 'item')
1.59 + try:
1.60 + cache_limit = int(getattr(request.cfg, 'page_cache_limit', "10"))
1.61 + except ValueError:
1.62 + cache_limit = 10
1.63 +
1.64 + if len(keys) >= cache_limit:
1.65 + items = [caching.CacheEntry(request, page, key, scope='item') for key in keys]
1.66 + item_ages = [(item.mtime(), item) for item in items]
1.67 + item_ages.sort()
1.68 + for item_age, item in item_ages[:-cache_limit]:
1.69 + item.remove()
1.70 +
1.71 +def getPageFormatterName(page, request=None):
1.72 +
1.73 + """
1.74 + Return a formatter name as used in the caching system for the given 'page'
1.75 + or using information provided by an optional 'request'.
1.76 + """
1.77 +
1.78 + formatter = getattr(page, 'formatter', None) or request and getattr(request, 'formatter', None)
1.79 + if not formatter:
1.80 + return ''
1.81 + module = formatter.__module__
1.82 + return module[module.rfind('.') + 1:]
1.83 +
1.84 # Page parsing and formatting of embedded content.
1.85
1.86 def getOutputTypes(request, format):