[CalendarServer-changes] [2535] CalendarServer/branches/memcache-reconnect-2/twistedcaldav/memcacher .py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Jun 4 10:54:37 PDT 2008
Revision: 2535
http://trac.macosforge.org/projects/calendarserver/changeset/2535
Author: dreid at apple.com
Date: 2008-06-04 10:54:35 -0700 (Wed, 04 Jun 2008)
Log Message:
-----------
Make memcacher use the pool until I figure out what do instead of memcacher.
Modified Paths:
--------------
CalendarServer/branches/memcache-reconnect-2/twistedcaldav/memcacher.py
Modified: CalendarServer/branches/memcache-reconnect-2/twistedcaldav/memcacher.py
===================================================================
--- CalendarServer/branches/memcache-reconnect-2/twistedcaldav/memcacher.py 2008-06-04 17:01:22 UTC (rev 2534)
+++ CalendarServer/branches/memcache-reconnect-2/twistedcaldav/memcacher.py 2008-06-04 17:54:35 UTC (rev 2535)
@@ -18,11 +18,11 @@
from twisted.internet.protocol import ClientCreator
from twistedcaldav.log import LoggingMixIn
-from twistedcaldav.memcache import MemCacheProtocol
+from twistedcaldav.memcachepool import CachePoolUserMixIn
from twistedcaldav.config import config
import cPickle
-class Memcacher(LoggingMixIn):
+class Memcacher(LoggingMixIn, CachePoolUserMixIn):
class memoryCacher():
"""
@@ -31,17 +31,17 @@
for caching on a single instance server, and for tests, where
memcached may not be running.
"""
-
+
def __init__(self):
self._cache = {}
def set(self, key, value):
self._cache[key] = value
return succeed(True)
-
+
def get(self, key):
return succeed((0, self._cache.get(key, None),))
-
+
def delete(self, key):
try:
del self._cache[key]
@@ -59,13 +59,13 @@
A class implementing the memcache client API we care about but
does not actually cache anything.
"""
-
+
def set(self, key, value):
return succeed(True)
-
+
def get(self, key):
return succeed((0, None,))
-
+
def delete(self, key):
return succeed(True)
@@ -82,85 +82,55 @@
nullCacher will be used for the multi-instance case when memcached is not configured.
@type no_invalidation: C{bool}
"""
-
self._memcacheProtocol = None
-
self._namespace = namespace
self._pickle = pickle
self._noInvalidation = no_invalidation
- self._host = config.Memcached['BindAddress']
- self._port = config.Memcached['Port']
- from twisted.internet import reactor
- self._reactor = reactor
-
def _getMemcacheProtocol(self):
if self._memcacheProtocol is not None:
- return succeed(self._memcacheProtocol)
+ return self._memcacheProtocol
if config.Memcached['ClientEnabled']:
- d = ClientCreator(self._reactor, MemCacheProtocol).connectTCP(
- self._host,
- self._port)
-
- def _cacheProtocol(proto):
- self._memcacheProtocol = proto
- return proto
-
- return d.addCallback(_cacheProtocol)
+ return self.getCachePool()
elif config.ProcessType == "Single" or self._noInvalidation:
-
+
# NB no need to pickle the memory cacher as it handles python types natively
self._memcacheProtocol = Memcacher.memoryCacher()
self._pickle = False
- return succeed(self._memcacheProtocol)
+ return self._memcacheProtocol
else:
-
+
# NB no need to pickle the null cacher as it handles python types natively
self._memcacheProtocol = Memcacher.nullCacher()
self._pickle = False
- return succeed(self._memcacheProtocol)
+ return self._memcacheProtocol
+
def set(self, key, value):
+ my_value = value
+ if self._pickle:
+ my_value = cPickle.dumps(value)
+ return self._getMemcacheProtocol().set(
+ '%s:%s' % (self._namespace, key), my_value)
- def _set(proto):
- my_value = value
- if self._pickle:
- my_value = cPickle.dumps(value)
- return proto.set('%s:%s' % (self._namespace, key), my_value)
-
- self.log_debug("Changing Cache Token for %s" % (key,))
- d = self._getMemcacheProtocol()
- d.addCallback(_set)
- return d
-
def get(self, key):
-
def _gotit(result):
_ignore_flags, value = result
if self._pickle and value is not None:
value = cPickle.loads(value)
return value
- def _get(proto):
- d1 = proto.get('%s:%s' % (self._namespace, key))
- d1.addCallback(_gotit)
- return d1
-
self.log_debug("Getting Cache Token for %r" % (key,))
- d = self._getMemcacheProtocol()
- d.addCallback(_get)
+ d = self._getMemcacheProtocol().get('%s:%s' % (self._namespace, key))
+ d.addCallback(_gotit)
return d
- def delete(self, key):
-
- def _delete(proto):
- return proto.delete('%s:%s' % (self._namespace, key))
+ def delete(self, key):
self.log_debug("Deleting Cache Token for %r" % (key,))
- d = self._getMemcacheProtocol()
- d.addCallback(_delete)
- return d
+ return self._getMemcacheProtocol().delete(
+ '%s:%s' % (self._namespace, key))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080604/66269ed2/attachment-0001.htm
More information about the calendarserver-changes
mailing list