app/soc/modules/core.py
changeset 2833 5aa891de5aa5
parent 2404 4f87bab3c6b3
child 2849 c0462a1d3958
--- a/app/soc/modules/core.py	Thu Aug 27 20:34:43 2009 -0700
+++ b/app/soc/modules/core.py	Fri Aug 28 11:45:55 2009 -0700
@@ -21,6 +21,8 @@
   ]
 
 
+import logging
+
 from django.conf.urls import defaults
 
 import settings
@@ -108,6 +110,7 @@
 
     self.sitemap = []
     self.sidebar = []
+    self.per_request_cache = {}
 
   ##
   ## internal
@@ -135,6 +138,36 @@
   ## Core code
   ##
 
+  def startNewRequest(self, request):
+    """Prepares core to handle a new request.
+    """
+
+    self.per_request_value = {}
+    self.setRequestValue('request', request)
+
+  def endRequest(self, request):
+    """Performs cleanup after current request.
+    """
+
+    old_request = self.getRequestValue('request')
+    self.per_request_value = {}
+
+    if id(old_request) != id(request):
+      logging.error("ending request: \n'%s'\n != \n'%s'\n" % (
+          old_request, request))
+
+  def getRequestValue(self, key, default=None):
+    """Gets a per-request value.
+    """
+
+    return self.per_request_value.get(key, default)
+
+  def setRequestValue(self, key, value):
+    """Sets a per-request value.
+    """
+
+    self.per_request_value[key] = value
+
   def getPatterns(self):
     """Returns the Django patterns for this site.
     """