[CalendarServer-changes] [6910] CalendarServer/trunk/txdav/base/propertystore/sql.py
source_changes at macosforge.org
source_changes at macosforge.org
Mon Feb 7 17:31:54 PST 2011
Revision: 6910
http://trac.macosforge.org/projects/calendarserver/changeset/6910
Author: cdaboo at apple.com
Date: 2011-02-07 17:31:52 -0800 (Mon, 07 Feb 2011)
Log Message:
-----------
Cache resource properties via memcached to avoid SQL queries.
Modified Paths:
--------------
CalendarServer/trunk/txdav/base/propertystore/sql.py
Modified: CalendarServer/trunk/txdav/base/propertystore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/base/propertystore/sql.py 2011-02-07 22:53:34 UTC (rev 6909)
+++ CalendarServer/trunk/txdav/base/propertystore/sql.py 2011-02-08 01:31:52 UTC (rev 6910)
@@ -14,7 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
##
-from twisted.internet.defer import inlineCallbacks, returnValue
"""
PostgreSQL data store.
@@ -24,13 +23,19 @@
"PropertyStore",
]
+from twistedcaldav.memcacher import Memcacher
+
from txdav.base.propertystore.base import AbstractPropertyStore, PropertyName,\
validKey
from twext.web2.dav.davxml import WebDAVDocument
+from twisted.internet.defer import inlineCallbacks, returnValue
+
class PropertyStore(AbstractPropertyStore):
+ cacher = Memcacher("propertystore.sql", pickle=True)
+
def __init__(self, *a, **kw):
raise NotImplementedError(
"do not construct directly, call PropertyStore.load()"
@@ -46,16 +51,25 @@
self._resourceID = resourceID
self._cached = {}
if not created:
- # Cache existing properties
- rows = yield self._txn.execSQL(
- """
- select NAME, VIEWER_UID, VALUE from RESOURCE_PROPERTY
- where RESOURCE_ID = %s
- """,
- [self._resourceID]
- )
+
+ # Cache existing properties in this object
+
+ # Look for memcache entry first
+ rows = yield self.cacher.get(str(self._resourceID))
+
+ if rows is None:
+ rows = yield self._txn.execSQL(
+ """
+ select NAME, VIEWER_UID, VALUE from RESOURCE_PROPERTY
+ where RESOURCE_ID = %s
+ """,
+ [self._resourceID]
+ )
+ yield self.cacher.set(str(self._resourceID), rows if rows is not None else ())
for name, uid, value in rows:
self._cached[(name, uid)] = value
+
+
returnValue(self)
@classmethod
@@ -137,8 +151,8 @@
[self._resourceID, key_str, value_str, uid]
)
self._cached[(key_str, uid)] = value_str
+ self.cacher.delete(str(self._resourceID))
-
def _delitem_uid(self, key, uid):
validKey(key)
@@ -152,6 +166,7 @@
[self._resourceID, key_str, uid],
raiseOnZeroRowCount=lambda:KeyError(key)
)
+ self.cacher.delete(str(self._resourceID))
def _keys_uid(self, uid):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110207/273a2fb5/attachment.html>
More information about the calendarserver-changes
mailing list