changeset 3801:7eb4a14108de

sendcached: add missing request param, add is_cached() function
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 28 Jun 2008 14:29:11 +0200
parents 07ea9c357b2a
children 88b2eecd1fed
files MoinMoin/action/sendcached.py
diffstat 1 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/sendcached.py	Fri Jun 27 18:52:24 2008 +0200
+++ b/MoinMoin/action/sendcached.py	Sat Jun 28 14:29:11 2008 +0200
@@ -111,6 +111,29 @@
     return get_url(request, key)
 
 
+def is_cached(request, key, strict=False):
+    """
+    Check if we have already cached an object for this key.
+
+    @param request: the request object
+    @param key: non-guessable key into sendcached cache (str)
+    @param strict: if True, also check the data cache, not only meta (bool, default: False)
+    @return: is object cached? (bool)
+    """
+    if strict:
+        data_cache = caching.CacheEntry(request, sendcached_arena, key+'.data',
+                                        sendcached_scope, do_locking=do_locking)
+        data_cached = data_cache.exists()
+    else:
+        data_cached = True  # we assume data will be there if meta is there
+
+    meta_cache = caching.CacheEntry(request, sendcached_arena, key+'.meta',
+                                    sendcached_scope, do_locking=do_locking, use_pickle=True)
+    meta_cached = meta_cache.exists()
+
+    return meta_cached and data_cached
+
+
 def get_url(request, key):
     """ get URL for the object cached for key """
     return "%s/?%s" % (
@@ -146,5 +169,5 @@
 
 def execute(pagename, request):
     key = request.form.get('key', [None])[0]
-    send_cached(key)
+    send_cached(request, key)