def set(cls,name,value, useMemoryCache=True): if useMemoryCache: global _settingcache _settingcache[name] = value memcache.set("setting.%s" % name, value, 0) opt = Setting.get_or_insert(name) opt.name = name opt.value = pickle.dumps(value) opt.put()
def cached_func(*args, **kw): key_with_suffix = key if key_suffix_calc_func: key_suffix = key_suffix_calc_func(*args, **kw) if key_suffix is not None: key_with_suffix = '%s:%s' % (key, key_suffix) value = memcache.get(key_with_suffix, namespace) if value is None: value = func(*args, **kw) try: memcache.set(key_with_suffix, value, cache_time, namespace) except: pass return value
def get(cls,name,default=None, useMemoryCache=True): global _settingcache if useMemoryCache and _settingcache.has_key(name) : return _settingcache[name] else: n = memcache.get("setting.%s" % name) if n != None: if useMemoryCache: _settingcache[name] = n return n try: opt=Setting.get_by_key_name(name) result = pickle.loads(str(opt.value)) if isinstance(result, unicode): result = result.encode("utf-8") if useMemoryCache: _settingcache[name] = result memcache.set("setting.%s" % name, result, 0) return result except: return default