diff --git a/README.rst b/README.rst index cf85381..e6c785a 100644 --- a/README.rst +++ b/README.rst @@ -30,6 +30,7 @@ Here's an example:: 'MAX_POOL_SIZE': 100, 'BLACKLIST_TIME': 20, 'SOCKET_TIMEOUT': 5, + 'MAX_ITEM_SIZE': 1000*100, } } } @@ -40,5 +41,5 @@ Options: - **MAX_POOL_SIZE:** -- The maximum number of connectors in the pool. default: 35. - **BLACKLIST_TIME** -- The time in seconds a server stays in the blacklist. default: 60 - **SOCKET_TIMEOUT** -- the time in seconds for the socket timeout. default: 4 - +- **MAX_ITEM_SIZE** -- The maximum size for an item in Memcache. diff --git a/memcachepool/cache.py b/memcachepool/cache.py index db62277..ac17696 100644 --- a/memcachepool/cache.py +++ b/memcachepool/cache.py @@ -13,6 +13,9 @@ from memcachepool.pool import ClientPool +DEFAULT_ITEM_SIZE = 1000 * 1000 + + # XXX using python-memcached style pickling # but maybe we could use something else like # json @@ -39,6 +42,8 @@ def __init__(self, server, params): self.maxsize = int(params.get('MAX_POOL_SIZE', 35)) self.blacklist_time = int(params.get('BLACKLIST_TIME', 60)) self.socktimeout = int(params.get('SOCKET_TIMEOUT', 4)) + self.max_item_size = long(params.get('MAX_ITEM_SIZE', + DEFAULT_ITEM_SIZE)) self._pool = ClientPool(self._get_client, maxsize=self.maxsize) self._blacklist = {} @@ -63,30 +68,10 @@ def _get_client(self): server = self._pick_server() last_error = None - # until my merge makes it upstream - # see : https://github.com/esnme/ultramemcache/pull/9 - # - # we are going to fallback on the poor's man technique - # to define the socket timeout. - # - # Unfortunately, this change impacts all sockets created - # in the interim in the same process, but that should - # not be a problem since we'll usually set this - # timeout to 5 seconds, which is long enough for any - # protocol - if hasattr(self._lib.Client, 'sock'): # NOQA - def create_client(server): - cli = self._lib.Client(server) - cli.sock.settimeout(self.socktimeout) - return cli - else: - def create_client(client): # NOQA - old = socket.getdefaulttimeout() - socket.setdefaulttimeout(self.socktimeout) - try: - return self._lib.Client(server) - finally: - socket.setdefaulttimeout(old) + def create_client(server): + cli = self._lib.Client(server, max_item_size=self.max_item_size) + cli.sock.settimeout(self.socktimeout) + return cli while server is not None: cli = create_client(server)