def _is_in_list(web_address): address = get_from_cache(web_address) if address is None: address = AccessWhiteList.objects(address=web_address).first() if address: return True return False
def _cache_controlled(*args, **kw): _request_key = None ''' search for cache key in the @cache annotation. return key value ''' _cache_key = get_cache_key(kwargs) if _cache_key: ''' generate request key based on cache key. returns None if nil ''' _request_key = make_request_key(_cache_key, kw) if _request_key: start_execution_time = time.time() ''' get value from cache ''' cache_response = get_from_cache(_request_key) end_execution_time = time.time() if cache_response: ''' calculate execution time ''' if DEBUG_LEVEL: dt = int((end_execution_time - start_execution_time)*1000) if dt>2: print "WARNING: To get value from cache took "+str(dt)+" msecs to execute" return cache_response ''' return original function ''' response = viewfunc(*args, **kw) ''' save key in cache if key is valid''' if _request_key: ttl = get_key_ttl(kwargs) if ttl == 0: ttl = five_minutes_in_seconds save_in_cache(_request_key, response, ttl) return response