Skip to content

Commit

Permalink
use env var EMPTY_CACHE_TIMEOUT
Browse files Browse the repository at this point in the history
  • Loading branch information
kantai committed Oct 30, 2018
1 parent a16affa commit a4bef8e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def str2bool(s):
# DEFAULT_CACHE_TIMEOUT determines the
DEFAULT_CACHE_TIMEOUT = int(os.getenv('DEFAULT_CACHE_TIMEOUT','43200')) # 12 hours in seconds

EMPTY_CACHE_TIMEOUT = int(os.getenv('EMPTY_CACHE_TIMEOUT','60')) # 1 minute

# DEBUG increases logging verbosity
DEBUG = str2bool(os.getenv('DEBUG','False'))

Expand Down
6 changes: 3 additions & 3 deletions api/search/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from flask import request, jsonify, make_response, render_template, Blueprint
from flask_crossdomain import crossdomain

from api.config import DEFAULT_HOST, DEFAULT_PORT, DEBUG, DEFAULT_CACHE_TIMEOUT
from api.config import DEFAULT_HOST, DEFAULT_PORT, DEBUG, DEFAULT_CACHE_TIMEOUT, EMPTY_CACHE_TIMEOUT
from api.config import SEARCH_DEFAULT_LIMIT as DEFAULT_LIMIT

from .substring_search import search_people_by_name, search_people_by_twitter
Expand Down Expand Up @@ -159,9 +159,9 @@ def search_by_name():

resp = make_response(jsonify(results))
if len(results['results']) > 0:
cache_timeout = DEFAULT_CACHE_TIMEOUT)
cache_timeout = DEFAULT_CACHE_TIMEOUT
else:
cache_timeout = 60
cache_timeout = EMPTY_CACHE_TIMEOUT

resp.headers['Cache-Control'] = 'public, max-age={:d}'.format(cache_timeout)

Expand Down

0 comments on commit a4bef8e

Please sign in to comment.