Commit 8b0f1a03 by Victor Shnayder

get rid of caching--unneeded complexity.

parent 671f2af3
...@@ -14,28 +14,16 @@ log = logging.getLogger(__name__) ...@@ -14,28 +14,16 @@ log = logging.getLogger(__name__)
def get_site_status_msg(): def get_site_status_msg():
""" """
Look for a file settings.STATUS_MESSAGE_PATH. If found, return the Look for a file settings.STATUS_MESSAGE_PATH. If found, return the
contents. Otherwise, return None. Caches result for 10 seconds, per-machine. contents. Otherwise, return None.
If something goes wrong, returns None. ("is there a status msg?" logic is If something goes wrong, returns None. ("is there a status msg?" logic is
not allowed to break the entire site). not allowed to break the entire site).
""" """
cache_time = 10
try: try:
key = ','.join([settings.HOSTNAME, settings.STATUS_MESSAGE_PATH]) content = None
content = cache.get(key) if os.path.isfile(settings.STATUS_MESSAGE_PATH):
if content == '': with open(settings.STATUS_MESSAGE_PATH) as f:
# cached that there isn't a status message content = f.read()
return None
if content is None:
# nothing in the cache, so check the filesystem
if os.path.isfile(settings.STATUS_MESSAGE_PATH):
with open(settings.STATUS_MESSAGE_PATH) as f:
content = f.read()
else:
# remember that there isn't anything there
cache.set(key, '', cache_time)
content = None
return content return content
except: except:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment