def put_to_cachestore(self, store_id, method, path, data=None, need_token=True, user_relative=False, use_cache=True, store_prefix=None, user_store=False): from app.utils import CacheRouter cache = CacheRouter() if cache.r is not None: key_data = cache.generate_key(data_type='rest', path=path, data=data, user_relative=user_relative) cache.put_data(key_data, key_prefix=store_prefix, data_type='store', store_id=store_id, user_store=user_store) print "~Cachelog: put_to_cachestore:", store_id, store_prefix
def send(self, method, path, data=None, need_token=True, user_relative=False, use_cache=True, token=None): if use_cache: from app.utils import CacheRouter method = method.upper() cache = CacheRouter() if cache.r is not None: if method in ['GET']: cached_data = cache.get_data(data_type='rest', path=path, data=data, user_relative=user_relative) if cached_data is not None: return json.loads(cached_data) else: rest_data = super(CachedRestObject, self).send(method, path, data, need_token, token) if rest_data: cache.put_data(json.dumps(rest_data), data_type='rest', path=path, data=data, user_relative=user_relative) return rest_data if method in ['PUT', 'PATCH', 'DELETE']: cache.free_data(data_type='rest', path=path, user_relative=user_relative) return super(CachedRestObject, self).send(method, path, data, need_token, token) else: return super(CachedRestObject, self).send(method, path, data, need_token, token) else: return super(CachedRestObject, self).send(method, path, data, need_token, token)
def free_cachestore(store_id, user_relative=False, store_prefix=None, user_store=False): from app.utils import CacheRouter cache = CacheRouter() if cache.r is not None: cache.free_data(key_prefix=store_prefix, data_type='store', store_id=store_id, user_store=False) print "~Cachelog: free_cachestore:", store_id, store_prefix