Esempio n. 1
0
 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))
Esempio n. 2
0
 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
Esempio n. 3
0
 def get(self, key, default=None):
     val = self._cache.get(smart_str(key))
     if val is None:
         return default
     return val
Esempio n. 4
0
 def append(self, key, value, timeout=None):
     self._cache.append(smart_str(key), value,
                        self._get_memcache_timeout(timeout))
Esempio n. 5
0
 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))