Commit 7e1c3083 authored by Markus Kaiserswerth's avatar Markus Kaiserswerth

Allow timeout=None, fixes #62

parent 4a0911a5
...@@ -208,7 +208,7 @@ class CacheClass(BaseCache): ...@@ -208,7 +208,7 @@ class CacheClass(BaseCache):
return result return result
def _set(self, key, value, timeout, client, _add_only=False): def _set(self, key, value, timeout, client, _add_only=False):
if timeout == 0: if timeout is None or timeout == 0:
if _add_only: if _add_only:
return client.setnx(key, value) return client.setnx(key, value)
return client.set(key, value) return client.set(key, value)
...@@ -231,12 +231,14 @@ class CacheClass(BaseCache): ...@@ -231,12 +231,14 @@ class CacheClass(BaseCache):
key = self.make_key(key, version=version) key = self.make_key(key, version=version)
if timeout is DEFAULT_TIMEOUT: if timeout is DEFAULT_TIMEOUT:
timeout = self.default_timeout timeout = self.default_timeout
if timeout is not None:
timeout = int(timeout)
# If ``value`` is not an int, then pickle it # If ``value`` is not an int, then pickle it
if not isinstance(value, int) or isinstance(value, bool): if not isinstance(value, int) or isinstance(value, bool):
result = self._set(key, pickle.dumps(value), int(timeout), client, _add_only) result = self._set(key, pickle.dumps(value), timeout, client, _add_only)
else: else:
result = self._set(key, value, int(timeout), client, _add_only) result = self._set(key, value, timeout, client, _add_only)
# result is a boolean # result is a boolean
return result return result
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment