Commit d6b357de authored by Ales Zoulek's avatar Ales Zoulek

call set_many in pipeline

parent df5d6063
...@@ -113,10 +113,12 @@ class CacheClass(BaseCache): ...@@ -113,10 +113,12 @@ class CacheClass(BaseCache):
return default return default
return self.unpickle(value) return self.unpickle(value)
def set(self, key, value, timeout=None, version=None): def set(self, key, value, timeout=None, version=None, client=None):
""" """
Persist a value to the cache, and set an optional expiration time. Persist a value to the cache, and set an optional expiration time.
""" """
if not client:
client = self._cache
key = self.make_key(key, version=version) key = self.make_key(key, version=version)
# get timout # get timout
if not timeout: if not timeout:
...@@ -190,13 +192,10 @@ class CacheClass(BaseCache): ...@@ -190,13 +192,10 @@ class CacheClass(BaseCache):
If timeout is given, that timeout will be used for the key; otherwise If timeout is given, that timeout will be used for the key; otherwise
the default cache timeout will be used. the default cache timeout will be used.
""" """
safe_data = {} pipeline = self._cache.pipeline()
for key, value in data.iteritems(): for key, value in data.iteritems():
safe_data[key] = pickle.dumps(value) self.set(key, value, timeout, version=version, client=pipeline)
if safe_data: pipeline.execute()
self._cache.mset(dict((self.make_key(key, version=version), value)
for key, value in safe_data.iteritems()))
map(self.expire, safe_data, [timeout]*len(safe_data))
class RedisCache(CacheClass): class RedisCache(CacheClass):
......
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