def _memchache_get_comic_by_type_group(callback, string_content = 'getcomicbytypegroup', time = 5): "memcache缓存,time默认为5分钟" #hash一下,为了key键分布更均衡 key = md5(string_content.encode('UTF-16')).hexdigest() res = mc.get(key) if not res: res = _get_comic_by_type_group() mc.set(key, res, time * 60) res = callback + '(' + res + ')' return res
def _memchache_get_records(query_sql, time = 5): "memcache缓存,time默认为5分钟" #hash一下,为了key键分布更均衡 key = md5(query_sql.encode('UTF-16')).hexdigest() res = mc.get(key) if not res: res = db.query(query_sql).list() mc.set(key, res, 60 * time) #存5分钟 res = db.query(query_sql).list() return res
def set(self, name, value): return mc.set(name, pickle.dumps(value))