|
|
|
@ -34,8 +34,16 @@ def get_signature(user_agent, query_string, client_ip_address, lang):
|
|
|
|
|
"""
|
|
|
|
|
Get cache signature based on `user_agent`, `url_string`,
|
|
|
|
|
`lang`, and `client_ip_address`
|
|
|
|
|
Return `None` if query should not be cached.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
if "?" in query_string:
|
|
|
|
|
location = query_string.split("?", 1)[0]
|
|
|
|
|
else:
|
|
|
|
|
location = query_string
|
|
|
|
|
if ":" in location:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
signature = "%s:%s:%s:%s" % \
|
|
|
|
|
(user_agent, query_string, client_ip_address, lang)
|
|
|
|
|
print(signature)
|
|
|
|
@ -48,6 +56,9 @@ def get(signature):
|
|
|
|
|
the `_update_answer` function.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
if not signature:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
value_record = CACHE.get(signature)
|
|
|
|
|
if not value_record:
|
|
|
|
|
return None
|
|
|
|
@ -69,6 +80,8 @@ def store(signature, value):
|
|
|
|
|
"""
|
|
|
|
|
Store in cache `value` for `signature`
|
|
|
|
|
"""
|
|
|
|
|
if not signature:
|
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
if len(value) >= MIN_SIZE_FOR_FILECACHE:
|
|
|
|
|
value_to_store = _store_in_file(signature, value)
|
|
|
|
|