[CalendarServer-changes] [2378] CalendarServer/branches/propfind-cache-2/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Wed May 7 11:19:28 PDT 2008


Revision: 2378
          http://trac.macosforge.org/projects/calendarserver/changeset/2378
Author:   dreid at apple.com
Date:     2008-05-07 11:19:27 -0700 (Wed, 07 May 2008)

Log Message:
-----------
Share code and make the propfind caching more robust against subtle changes in resource heirarchy structure.

Modified Paths:
--------------
    CalendarServer/branches/propfind-cache-2/twistedcaldav/cache.py
    CalendarServer/branches/propfind-cache-2/twistedcaldav/config.py
    CalendarServer/branches/propfind-cache-2/twistedcaldav/directory/principal.py
    CalendarServer/branches/propfind-cache-2/twistedcaldav/root.py
    CalendarServer/branches/propfind-cache-2/twistedcaldav/static.py

Modified: CalendarServer/branches/propfind-cache-2/twistedcaldav/cache.py
===================================================================
--- CalendarServer/branches/propfind-cache-2/twistedcaldav/cache.py	2008-05-07 17:20:52 UTC (rev 2377)
+++ CalendarServer/branches/propfind-cache-2/twistedcaldav/cache.py	2008-05-07 18:19:27 UTC (rev 2378)
@@ -70,9 +70,11 @@
     CACHE_TIMEOUT = 60*60 #1hr
     propertyStoreFactory = xattrPropertyStore
 
-    def __init__(self, docroot):
+    def __init__(self, docroot, cacheTimeout=None):
         self._docroot = docroot
         self._responses = {}
+        if cacheTimeout:
+            self.CACHE_TIMEOUT = cacheTimeout
 
 
     def _tokenForURI(self, uri):
@@ -191,3 +193,23 @@
 
     def locateChild(self, request, segments):
         return self, []
+
+
+class PropfindCacheMixin(object):
+    def http_PROPFIND(self, request):
+        def _cacheResponse(responseCache, response):
+            d2 = responseCache.cacheResponseForRequest(request, response)
+            d2.addCallback(
+                lambda ign: responseCache.getResponseForRequest(request))
+            return d2
+
+        def _getResponseCache(response):
+            print "Caching response: %r" % (response,)
+            d1 = request.locateResource("/")
+            d1.addCallback(lambda resource: resource.responseCache)
+            d1.addCallback(_cacheResponse, response)
+            return d1
+
+        d = super(PropfindCacheMixin, self).http_PROPFIND(request)
+        d.addCallback(_getResponseCache)
+        return d

Modified: CalendarServer/branches/propfind-cache-2/twistedcaldav/config.py
===================================================================
--- CalendarServer/branches/propfind-cache-2/twistedcaldav/config.py	2008-05-07 17:20:52 UTC (rev 2377)
+++ CalendarServer/branches/propfind-cache-2/twistedcaldav/config.py	2008-05-07 18:19:27 UTC (rev 2378)
@@ -182,6 +182,9 @@
 
     # Set the maximum number of outstanding requests to this server.
     "MaxRequests": 600,
+
+    # Configure the number of seconds that Propfinds should be cached for.
+    "ResponseCacheTimeout": 60*60, # 1 Hour.
 }
 
 class Config (object):

Modified: CalendarServer/branches/propfind-cache-2/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/branches/propfind-cache-2/twistedcaldav/directory/principal.py	2008-05-07 17:20:52 UTC (rev 2377)
+++ CalendarServer/branches/propfind-cache-2/twistedcaldav/directory/principal.py	2008-05-07 18:19:27 UTC (rev 2378)
@@ -41,7 +41,7 @@
 from twisted.web2.dav.util import joinURL
 
 from twistedcaldav.config import config
-from twistedcaldav.cache import CacheChangeNotifier
+from twistedcaldav.cache import CacheChangeNotifier, PropfindCacheMixin
 
 from twistedcaldav.directory.calendaruserproxy import CalendarUserProxyDatabase
 from twistedcaldav.directory.calendaruserproxy import CalendarUserProxyPrincipalResource
@@ -343,7 +343,7 @@
     def principalCollections(self):
         return self.parent.principalCollections()
 
-class DirectoryPrincipalResource (AutoProvisioningFileMixIn, PermissionsMixIn, DAVPrincipalResource, DAVFile):
+class DirectoryPrincipalResource (PropfindCacheMixin, AutoProvisioningFileMixIn, PermissionsMixIn, DAVPrincipalResource, DAVFile):
     """
     Directory principal resource.
     """
@@ -533,22 +533,9 @@
     def listChildren(self):
         return ()
 
-    def http_PROPFIND(self, request):
-        def _cacheResponse(response):
-            print "Caching response: %r" % (response,)
-            responseCache = request.site.resource.resource.resource.resource.responseCache
-            d1 = responseCache.cacheResponseForRequest(request, response)
-            d1.addCallback(
-                lambda ign: responseCache.getResponseForRequest(request))
-            return d1
 
-        d = super(DirectoryPrincipalResource, self).http_PROPFIND(request)
-        d.addCallback(_cacheResponse)
-        return d
 
 
-
-
 class DirectoryCalendarPrincipalResource (DirectoryPrincipalResource, CalendarPrincipalResource):
     """
     Directory calendar principal resource.

Modified: CalendarServer/branches/propfind-cache-2/twistedcaldav/root.py
===================================================================
--- CalendarServer/branches/propfind-cache-2/twistedcaldav/root.py	2008-05-07 17:20:52 UTC (rev 2377)
+++ CalendarServer/branches/propfind-cache-2/twistedcaldav/root.py	2008-05-07 18:19:27 UTC (rev 2378)
@@ -50,7 +50,7 @@
 
         self.contentFilters = []
 
-        self.responseCache = ResponseCache(self.fp)
+        self.responseCache = ResponseCache(self.fp, config.ResponseCacheTimeout)
 
         if config.ResponseCompression:
             from twisted.web2.filter import gzip

Modified: CalendarServer/branches/propfind-cache-2/twistedcaldav/static.py
===================================================================
--- CalendarServer/branches/propfind-cache-2/twistedcaldav/static.py	2008-05-07 17:20:52 UTC (rev 2377)
+++ CalendarServer/branches/propfind-cache-2/twistedcaldav/static.py	2008-05-07 18:19:27 UTC (rev 2378)
@@ -71,7 +71,7 @@
 from twistedcaldav.directory.calendar import DirectoryCalendarHomeResource
 from twistedcaldav.directory.resource import AutoProvisioningResourceMixIn
 
-from twistedcaldav.cache import CacheChangeNotifier
+from twistedcaldav.cache import CacheChangeNotifier, PropfindCacheMixin
 
 class CalDAVFile (CalDAVResource, DAVFile):
     """
@@ -522,7 +522,7 @@
     def createSimilarFile(self, path):
         raise HTTPError(responsecode.NOT_FOUND)
 
-class CalendarHomeFile (AutoProvisioningFileMixIn, DirectoryCalendarHomeResource, CalDAVFile):
+class CalendarHomeFile (PropfindCacheMixin, AutoProvisioningFileMixIn, DirectoryCalendarHomeResource, CalDAVFile):
     """
     Calendar home collection resource.
     """
@@ -571,19 +571,7 @@
 
         return super(CalendarHomeFile, self).getChild(name)
 
-    def http_PROPFIND(self, request):
-        def _cacheResponse(response):
-            print "Caching response: %r" % (response,)
-            responseCache = request.site.resource.resource.resource.resource.responseCache
-            d1 = responseCache.cacheResponseForRequest(request, response)
-            d1.addCallback(
-                lambda ign: responseCache.getResponseForRequest(request))
-            return d1
 
-        d = super(CalendarHomeFile, self).http_PROPFIND(request)
-        d.addCallback(_cacheResponse)
-        return d
-
 class ScheduleFile (AutoProvisioningFileMixIn, CalDAVFile):
     def __init__(self, path, parent):
         super(ScheduleFile, self).__init__(path, principalCollections=parent.principalCollections())

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080507/162f4466/attachment.html


More information about the calendarserver-changes mailing list