[CalendarServer-changes] [2373]
CalendarServer/branches/propfind-cache/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Tue May 6 10:42:03 PDT 2008
Revision: 2373
http://trac.macosforge.org/projects/calendarserver/changeset/2373
Author: dreid at apple.com
Date: 2008-05-06 10:42:02 -0700 (Tue, 06 May 2008)
Log Message:
-----------
Able to serve half a response from the cache.
Modified Paths:
--------------
CalendarServer/branches/propfind-cache/twistedcaldav/cache.py
CalendarServer/branches/propfind-cache/twistedcaldav/directory/principal.py
CalendarServer/branches/propfind-cache/twistedcaldav/root.py
CalendarServer/branches/propfind-cache/twistedcaldav/static.py
CalendarServer/branches/propfind-cache/twistedcaldav/test/test_cache.py
Modified: CalendarServer/branches/propfind-cache/twistedcaldav/cache.py
===================================================================
--- CalendarServer/branches/propfind-cache/twistedcaldav/cache.py 2008-05-06 14:20:14 UTC (rev 2372)
+++ CalendarServer/branches/propfind-cache/twistedcaldav/cache.py 2008-05-06 17:42:02 UTC (rev 2373)
@@ -65,6 +65,7 @@
"""
CACHE_TIMEOUT = 60*60 #1hr
+ propertyStoreFactory = xattrPropertyStore
def __init__(self, docroot):
self._docroot = docroot
@@ -98,6 +99,10 @@
pass
+ def _principalURI(self, principal):
+ return str(principal.children[0])
+
+
def _time(self):
"""
Return the current time in seconds since the epoch
@@ -115,13 +120,17 @@
@return: An L{IResponse} or C{None} if the response has not been cached.
"""
- key = (request.method, request.uri, request.authnUser)
+ principalURI = self._principalURI(request.authnUser)
+
+ key = (request.method,
+ request.uri,
+ principalURI)
if key not in self._responses:
return None
principalToken, uriToken, cacheTime, response = self._responses[key]
- if self._tokenForURI(request.authnUser) != principalToken:
+ if self._tokenForURI(principalURI) != principalToken:
return None
elif self._tokenForURI(request.uri) != uriToken:
@@ -143,7 +152,25 @@
@param response: An L{IResponse} provider that will be returned on
subsequent checks for the given L{IRequest}
"""
- key = (request.method, request.uri, request.authnUser)
- self._responses[key] = (self._tokenForURI(request.authnUser),
+ principalURI = self._principalURI(request.authnUser)
+
+ key = (request.method,
+ request.uri,
+ principalURI)
+
+ self._responses[key] = (self._tokenForURI(principalURI),
self._tokenForURI(request.uri),
self._time(), response)
+
+
+class _CachedResponseResource(object):
+ implements(IResource)
+
+ def __init__(self, response):
+ self._response = response
+
+ def renderHTTP(self, request):
+ return self._response
+
+ def locateChild(self, request, segments):
+ return self, []
Modified: CalendarServer/branches/propfind-cache/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/branches/propfind-cache/twistedcaldav/directory/principal.py 2008-05-06 14:20:14 UTC (rev 2372)
+++ CalendarServer/branches/propfind-cache/twistedcaldav/directory/principal.py 2008-05-06 17:42:02 UTC (rev 2373)
@@ -357,8 +357,7 @@
"""
super(DirectoryPrincipalResource, self).__init__(path)
- self.cacheNotifier = self.cacheNotifierFactory(
- self.deadProperties())
+ self.cacheNotifier = self.cacheNotifierFactory(self.deadProperties())
if self.isCollection():
slash = "/"
Modified: CalendarServer/branches/propfind-cache/twistedcaldav/root.py
===================================================================
--- CalendarServer/branches/propfind-cache/twistedcaldav/root.py 2008-05-06 14:20:14 UTC (rev 2372)
+++ CalendarServer/branches/propfind-cache/twistedcaldav/root.py 2008-05-06 17:42:02 UTC (rev 2373)
@@ -26,6 +26,7 @@
from twistedcaldav.extensions import DAVFile
from twistedcaldav.config import config
+from twistedcaldav.cache import ResponseCache, _CachedResponseResource
class RootResource(DAVFile):
"""
@@ -49,6 +50,8 @@
self.contentFilters = []
+ self.responseCache = ResponseCache(self.fp)
+
if config.ResponseCompression:
from twisted.web2.filter import gzip
self.contentFilters.append((gzip.gzipfilter, True))
@@ -108,6 +111,18 @@
return d
def locateChild(self, request, segments):
+ def _authCb((authnUser, authzUser)):
+ request.authnUser = authnUser
+ request.authzUser = authzUser
+
+ def _authEb(failure):
+ # Make sure we propogate UnauthorizedLogin errors.
+ failure.trap(UnauthorizedLogin, LoginFailed)
+
+ return Failure(HTTPError(UnauthorizedResponse(
+ request.credentialFactories,
+ request.remoteAddr)))
+
for filter in self.contentFilters:
request.addResponseFilter(filter[0], atEnd=filter[1])
@@ -118,6 +133,22 @@
return d
+ def _getCachedResource(_ign, request):
+ response = self.responseCache.getResponseForRequest(request)
+ assert response is not None
+ print "Serving from cache %r." % (response,)
+ return _CachedResponseResource(response), []
+
+ def _resourceNotInCacheEb(failure):
+ return super(RootResource, self).locateChild(request,segments)
+
+ if request.method == 'PROPFIND':
+ d = defer.maybeDeferred(self.authenticate, request)
+ d.addCallbacks(_authCb, _authEb)
+ d.addCallback(_getCachedResource, request)
+ d.addErrback(_resourceNotInCacheEb)
+ return d
+
return super(RootResource, self).locateChild(request, segments)
def http_COPY (self, request): return responsecode.FORBIDDEN
Modified: CalendarServer/branches/propfind-cache/twistedcaldav/static.py
===================================================================
--- CalendarServer/branches/propfind-cache/twistedcaldav/static.py 2008-05-06 14:20:14 UTC (rev 2372)
+++ CalendarServer/branches/propfind-cache/twistedcaldav/static.py 2008-05-06 17:42:02 UTC (rev 2373)
@@ -50,7 +50,7 @@
from twisted.web2.dav.method import put_common as put_common_base
from twisted.web2.dav.resource import AccessDeniedError
from twisted.web2.dav.resource import davPrivilegeSet
-from twisted.web2.dav.util import parentForURL, bindMethods
+from twisted.web2.dav.util import parentForURL, bindMethods, allDataFromStream
from twistedcaldav import caldavxml
from twistedcaldav import customxml
@@ -567,6 +567,17 @@
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
+ responseCache.cacheResponseForRequest(request, response)
+ return response
+
+ d = super(CalendarHomeFile, self).http_PROPFIND(request)
+ d.addBoth(_cacheResponse)
+ return d
+
class ScheduleFile (AutoProvisioningFileMixIn, CalDAVFile):
def __init__(self, path, parent):
super(ScheduleFile, self).__init__(path, principalCollections=parent.principalCollections())
@@ -600,6 +611,7 @@
(caldav_namespace, "calendar-collection-location-ok")
)
+
##
# ACL
##
Modified: CalendarServer/branches/propfind-cache/twistedcaldav/test/test_cache.py
===================================================================
--- CalendarServer/branches/propfind-cache/twistedcaldav/test/test_cache.py 2008-05-06 14:20:14 UTC (rev 2372)
+++ CalendarServer/branches/propfind-cache/twistedcaldav/test/test_cache.py 2008-05-06 17:42:02 UTC (rev 2373)
@@ -20,6 +20,8 @@
from twisted.python.filepath import FilePath
+from twisted.web2.dav import davxml
+
from twistedcaldav.cache import CacheChangeNotifier
from twistedcaldav.cache import CacheTokensProperty
from twistedcaldav.cache import ResponseCache
@@ -40,7 +42,7 @@
def __init__(self, method, uri, authnUser):
self.method = method
self.uri = uri
- self.authnUser = authnUser
+ self.authnUser = davxml.Principal(davxml.HRef.fromString(authnUser))
self.cacheRequest = False
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080506/ac9c23b2/attachment-0001.html
More information about the calendarserver-changes
mailing list