def set_many(self, data, timeout=None): safe_data = {} for key, value in data.items(): if isinstance(value, unicode): value = value.encode('utf-8') safe_data[smart_str(key)] = value self._cache.set_multi(safe_data, self._get_memcache_timeout(timeout))
def __setmembers(self, key): '''Mimic a set in memcached''' skey = smart_str(key) members = self.get(skey) if members: try: members = json.loads(members) except: raise BadCacheDataStructure('key %s does not contain a set' % key) else: members = [] return skey, members
def get(self, key, default=None): val = self._cache.get(smart_str(key)) if val is None: return default return val
def append(self, key, value, timeout=None): self._cache.append(smart_str(key), value, self._get_memcache_timeout(timeout))
def add(self, key, value, timeout=None): if isinstance(value, unicode): value = value.encode('utf-8') return self._cache.add(smart_str(key), value, self._get_memcache_timeout(timeout))