コード例 #1
0
ファイル: framework.py プロジェクト: PatrickKennedy/Sybil
		def wrapper(*args, **kwargs):
			cache_key = generate_cache_key(url, element, delinate)
			if refresh:
				unmemoize(url, element, delinate, delete_timeout)
			data = utils.deserialize_models(memcache.get(cache_key))
			if flush:
				unmemoize(url, element, delinate, delete_timeout)
			elif data is None:
				data = func(*args, **kwargs)
				memcache.set(cache_key, utils.serialize_models(data), timeout)
				logging.debug("Memoizing: %s(%s)" % (cache_key, url))
			return data
コード例 #2
0
ファイル: stores.py プロジェクト: PatrickKennedy/Sybil
	def get_by_key_name(cls, key_names, parent=None):
		# We need to perseve the return value if the input is a list
		# other wise we need to return just the entity itself.
		is_list = True
		# memcache.get_mutli() only accepts lists.
		if not isinstance(key_names, list):
			is_list = False
			key_names = [key_names]
		
		r = cls.__fill_blanks(key_names, memcache.get_multi(key_names))
		r = utils.deserialize_models(r)
		
		if not [x for x in r if x is not None]:
			r = super(ModelCaching, cls).get_by_key_name(key_names, parent)
			if r:
				logging.info("CACHING GET")
				if isinstance(r, db.Model):
					#logging.info('CACHING: %s' % r.key_name)
					memcache.set(r.key_name, utils.serialize_models(r))
				else:
					memcache.set_multi(dict([(x.key_name, utils.serialize_models(x)) for x in r if x]))
		return r if is_list else r[0]