[CalendarServer-changes] [2478] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Fri May 23 21:04:49 PDT 2008


Revision: 2478
          http://trac.macosforge.org/projects/calendarserver/changeset/2478
Author:   wsanchez at apple.com
Date:     2008-05-23 21:04:48 -0700 (Fri, 23 May 2008)

Log Message:
-----------
Add xattr cache to requests. (by dreid)

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/extensions.py
    CalendarServer/trunk/twistedcaldav/root.py
    CalendarServer/trunk/twistedcaldav/static.py

Modified: CalendarServer/trunk/twistedcaldav/extensions.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/extensions.py	2008-05-24 03:45:01 UTC (rev 2477)
+++ CalendarServer/trunk/twistedcaldav/extensions.py	2008-05-24 04:04:48 UTC (rev 2478)
@@ -47,6 +47,7 @@
 from twisted.web2.dav.resource import DAVResource as SuperDAVResource
 from twisted.web2.dav.resource import DAVPrincipalResource as SuperDAVPrincipalResource
 from twisted.web2.dav.util import joinURL
+from twisted.web2.dav.xattrprops import xattrPropertyStore
 
 from twistedcaldav.log import Logger, LoggingMixIn
 from twistedcaldav.util import submodule
@@ -695,6 +696,7 @@
              contentType,
          )
 
+
 class ReadOnlyWritePropertiesResourceMixIn (object):
     """
     Read only that will allow writing of properties resource.
@@ -731,3 +733,81 @@
         """
         Response.__init__(self, code, stream=element.toxml())
         self.headers.setHeader("content-type", MimeType("text", "xml"))
+
+
+
+class CachingXattrPropertyStore(xattrPropertyStore):
+    """
+    A Property Store that caches attributes from the xattrs.
+    """
+
+    def __init__(self, resource):
+        self._cache = {}
+        self._not_found = {}
+        super(CachingXattrPropertyStore, self).__init__(resource)
+
+
+    def get(self, qname):
+        if qname in self._cache:
+            log.debug("Cache hit: %r, %r, %r" % (self, self.resource.fp.path, qname))
+            return self._cache[qname]
+
+        if qname in self._not_found:
+            log.debug("Not found cache hit: %r, %r, %r" % (self, self.resource.fp.path, qname))
+            raise self._not_found[qname]
+
+        log.debug("Cache miss: %r, %r, %r" % (self, self.resource.fp.path, qname))
+
+        try:
+            property = super(CachingXattrPropertyStore, self).get(qname)
+        except HTTPError, err:
+            self._not_found[qname] = err
+            raise err
+
+        self._cache[qname] = property
+
+        return property
+
+
+    def set(self, property):
+        super(CachingXattrPropertyStore, self).set(property)
+        log.debug("Updating cache: %r, %r, %r" % (self, self.resource.fp.path, property.qname()))
+        self._cache[property.qname()] = property
+
+        if property.qname() in self._not_found:
+            del self._not_found[property.qname()]
+
+
+    def contains(self, qname):
+        if qname in self._cache:
+            log.debug("Contains cache hit: %r, %r, %r" % (self, self.resource.fp.path, qname))
+            return True
+
+        if qname in self._not_found:
+            log.debug("Contains not found cache hit: %r, %r, %r" % (self, self.resource.fp.path, qname))
+            return False
+
+        log.debug("Contains cache miss: %r, %r, %r" % (self, self.resource.fp.path, qname))
+
+        result = super(CachingXattrPropertyStore, self).contains(qname)
+
+        if result is False:
+            self._not_found[qname] = HTTPError(
+                StatusResponse(
+                    responsecode.NOT_FOUND,
+                    "No such property: {%s}%s" % (qname,)
+                )
+            )
+
+        return result
+
+
+    def delete(self, qname):
+        del self._not_found[qname]
+        del self._cache[qname]
+
+        super(CachingXattrPropertyStore, self).delete(qname)
+
+
+    def list(self):
+        return super(CachingXattrPropertyStore, self).list()

Modified: CalendarServer/trunk/twistedcaldav/root.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/root.py	2008-05-24 03:45:01 UTC (rev 2477)
+++ CalendarServer/trunk/twistedcaldav/root.py	2008-05-24 04:04:48 UTC (rev 2478)
@@ -23,7 +23,7 @@
 from twisted.web2.http import HTTPError
 from twisted.web2.auth.wrapper import UnauthorizedResponse
 
-from twistedcaldav.extensions import DAVFile
+from twistedcaldav.extensions import DAVFile, CachingXattrPropertyStore
 from twistedcaldav.config import config
 from twistedcaldav.cache import ResponseCache, _CachedResponseResource
 from twistedcaldav.cache import MemcacheResponseCache, MemcacheChangeNotifier
@@ -72,6 +72,12 @@
             from twisted.web2.filter import gzip
             self.contentFilters.append((gzip.gzipfilter, True))
 
+    def deadProperties(self):
+        if not hasattr(self, '_dead_properties'):
+            self._dead_properties = CachingXattrPropertyStore(self)
+
+        return self._dead_properties
+
     def checkSacl(self, request):
         """
         Check SACLs against the current request
@@ -126,6 +132,7 @@
         d.addCallback(_checkSACLCb)
         return d
 
+
     def locateChild(self, request, segments):
         def _authCb((authnUser, authzUser)):
             request.authnUser = authnUser

Modified: CalendarServer/trunk/twistedcaldav/static.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/static.py	2008-05-24 03:45:01 UTC (rev 2477)
+++ CalendarServer/trunk/twistedcaldav/static.py	2008-05-24 04:04:48 UTC (rev 2478)
@@ -55,6 +55,7 @@
 from twistedcaldav.caldavxml import caldav_namespace
 from twistedcaldav.config import config
 from twistedcaldav.extensions import DAVFile
+from twistedcaldav.extensions import CachingXattrPropertyStore
 from twistedcaldav.ical import Component as iComponent
 from twistedcaldav.ical import Property as iProperty
 from twistedcaldav.index import Index, IndexSchedule
@@ -84,6 +85,12 @@
         else:
             return super(CalDAVFile, self).__repr__()
 
+    def deadProperties(self):
+        if not hasattr(self, "_dead_properties"):
+            self._dead_properties = CachingXattrPropertyStore(self)
+
+        return self._dead_properties
+
     ##
     # CalDAV
     ##
@@ -409,9 +416,13 @@
 
 class AutoProvisioningFileMixIn (AutoProvisioningResourceMixIn):
     def provision(self):
-        self.provisionFile()
+        if hasattr(self, '_provisioned'):
+            self.provisionFile()
+            self._provisioned = True
+
         return super(AutoProvisioningFileMixIn, self).provision()
 
+
     def provisionFile(self):
         fp = self.fp
 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080523/0a00045e/attachment.htm 


More information about the calendarserver-changes mailing list