[CalendarServer-changes] [2505] CalendarServer/trunk/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Tue May 27 08:23:50 PDT 2008
Revision: 2505
http://trac.macosforge.org/projects/calendarserver/changeset/2505
Author: cdaboo at apple.com
Date: 2008-05-27 08:23:48 -0700 (Tue, 27 May 2008)
Log Message:
-----------
In some cases it is OK to use a memory cache in the multi-instance case when memcached is not present. That can be
done when the cache is static - i.e. no invalidations will occur. So add an option to indicate that.
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/memcacher.py
CalendarServer/trunk/twistedcaldav/test/test_memcacher.py
Modified: CalendarServer/trunk/twistedcaldav/memcacher.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/memcacher.py 2008-05-27 14:58:26 UTC (rev 2504)
+++ CalendarServer/trunk/twistedcaldav/memcacher.py 2008-05-27 15:23:48 UTC (rev 2505)
@@ -70,9 +70,22 @@
def delete(self, key):
return succeed(True)
- def __init__(self, namespace, pickle=False):
+ def __init__(self, namespace, pickle=False, no_invalidation=False):
+ """
+ @param namespace: a unique namespace for this cache's keys
+ @type namespace: C{str}
+ @param pickle: if C{True} values will be pickled/unpickled when stored/read from the cache,
+ if C{False} values will be stored directly (and therefore must be strings)
+ @type pickle: C{bool}
+ @param no_invalidation: if C{True} the cache is static - there will be no invalidations. This allows
+ Memcacher to use the memoryCacher cache instead of nullCacher for the multi-instance case when memcached
+ is not present,as there is no issue with caches in each instance getting out of sync. If C{False} the
+ nullCacher will be used for the multi-instance case when memcached is not configured.
+ @type no_invalidation: C{bool}
+ """
self._namespace = namespace
self._pickle = pickle
+ self._noInvalidation = no_invalidation
self._host = config.Memcached['BindAddress']
self._port = config.Memcached['Port']
@@ -95,7 +108,7 @@
return d.addCallback(_cacheProtocol)
- elif config.ProcessType == "Single":
+ elif config.ProcessType == "Single" or self._noInvalidation:
Memcacher._memcacheProtocol = Memcacher.memoryCacher()
return succeed(Memcacher._memcacheProtocol)
Modified: CalendarServer/trunk/twistedcaldav/test/test_memcacher.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_memcacher.py 2008-05-27 14:58:26 UTC (rev 2504)
+++ CalendarServer/trunk/twistedcaldav/test/test_memcacher.py 2008-05-27 15:23:48 UTC (rev 2505)
@@ -22,6 +22,7 @@
for processType in ("Single", "Combined",):
config.processType = processType
+ Memcacher._memcacheProtocol = None
cacher = Memcacher("testing")
result = yield cacher.set("akey", "avalue")
@@ -39,6 +40,7 @@
for processType in ("Single", "Combined",):
config.processType = processType
+ Memcacher._memcacheProtocol = None
cacher = Memcacher("testing")
result = yield cacher.get("akey")
@@ -50,6 +52,7 @@
for processType in ("Single", "Combined",):
config.processType = processType
+ Memcacher._memcacheProtocol = None
cacher = Memcacher("testing")
result = yield cacher.set("akey", "avalue")
@@ -73,6 +76,7 @@
for processType in ("Single", "Combined",):
config.processType = processType
+ Memcacher._memcacheProtocol = None
cacher = Memcacher("testing", pickle=True)
result = yield cacher.set("akey", ["1", "2", "3",])
@@ -90,3 +94,24 @@
result = yield cacher.get("akey")
self.assertEquals(None, result)
+ @inlineCallbacks
+ def test_all_noinvalidation(self):
+
+ for processType in ("Single", "Combined",):
+ config.processType = processType
+
+ Memcacher._memcacheProtocol = None
+ cacher = Memcacher("testing", no_invalidation=True)
+
+ result = yield cacher.set("akey", ["1", "2", "3",])
+ self.assertTrue(result)
+
+ result = yield cacher.get("akey")
+ self.assertEquals(["1", "2", "3",], result)
+
+ result = yield cacher.delete("akey")
+ self.assertTrue(result)
+
+ result = yield cacher.get("akey")
+ self.assertEquals(None, result)
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080527/547dfd51/attachment.htm
More information about the calendarserver-changes
mailing list