--- /home/festifn/moin/moin/MoinMoin/stats/hitcounts.py	Thu Jul 18 21:20:52 2002
+++ stats/hitcounts.py	Mon Dec 16 19:32:03 2002
@@ -47,6 +47,23 @@
     if request and request.form and request.form.has_key('page'):
         filterpage = request.form['page'].value
 
+    # try cache
+    if hasattr(config, "hitcounts_caching"):
+        from MoinMoin import caching
+        import time
+        arena = "stats"
+        if filterpage: key = "hitcount" + filterpage
+        else: key = "hitcount"
+        cache = caching.CacheEntry(arena, key)
+        if cache.exists() and (time.time() - cache.mtime() < config.hitcounts_caching):
+            headers = [
+                "Content-Type: image/gif",
+                "Content-Length: %d" % len(cache.content()),
+                ]
+            webapi.http_headers(request, headers)
+            sys.stdout.write(cache.content())
+            return        
+
     # prepare data
     days = []
     views = []
@@ -126,5 +143,7 @@
     # copy the image
     image.reset()
     shutil.copyfileobj(image, sys.stdout, 8192)
+    if hasattr(config, "hitcounts_caching"):
+        cache.update(image.getvalue())
     sys.exit(0)
 
