changeset 3800:07ea9c357b2a

sendcached: made some functions for usage from other modules, added comments
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 27 Jun 2008 18:52:24 +0200
parents 738bd5aec961
children 7eb4a14108de
files MoinMoin/action/sendcached.py
diffstat 1 files changed, 21 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/sendcached.py	Fri Jun 27 18:27:14 2008 +0200
+++ b/MoinMoin/action/sendcached.py	Fri Jun 27 18:52:24 2008 +0200
@@ -112,24 +112,39 @@
 
 
 def get_url(request, key):
+    """ get URL for the object cached for key """
     return "%s/?%s" % (
         request.getScriptname(),
         wikiutil.makeQueryString(dict(action=action_name, key=key), want_unicode=False))
 
 
-def execute(pagename, request):
-    key = request.form.get('key', [None])[0]
+def get_cache_headers(request, key):
+    """ get last_modified and headers cached for key """
     meta_cache = caching.CacheEntry(request, sendcached_arena, key+'.meta',
                                     sendcached_scope, do_locking=do_locking, use_pickle=True)
     last_modified, headers = meta_cache.content()
+    return last_modified, headers
 
+
+def get_cache_datafile(request, key):
+    """ get an open data file for the data cached for key """
+    data_cache = caching.CacheEntry(request, sendcached_arena, key+'.data',
+                                    sendcached_scope, do_locking=do_locking)
+    data_file = open(data_cache._filename(), 'rb')
+    return data_file
+
+
+def send_cached(request, key):
+    """ send a complete http response with headers/data cached for key """
+    last_modified, headers = get_cache_headers(request, key)
     if request.if_modified_since == last_modified:
         request.emit_http_headers(["Status: 304 Not modified"])
     else:
         request.emit_http_headers(headers)
+        request.send_file(get_cache_datafile(request, key))
 
-        data_cache = caching.CacheEntry(request, sendcached_arena, key+'.data',
-                                        sendcached_scope, do_locking=do_locking)
-        data_file = open(data_cache._filename(), 'rb')
-        request.send_file(data_file)
 
+def execute(pagename, request):
+    key = request.form.get('key', [None])[0]
+    send_cached(key)
+