Skip to content

Commit 681ac24

Browse files
authored
Merge pull request #229 from nih-sparc/cache-get-featured-dataset-endpoint-response
added caching to get featured dataset endpoint
2 parents 17abcf7 + e55982c commit 681ac24

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

app/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from pennsieve.base import UnauthorizedException as PSUnauthorizedException
3232
from PIL import Image
3333
from requests.auth import HTTPBasicAuth
34+
from flask_caching import Cache
3435

3536
from app.scicrunch_requests import create_doi_query, create_filter_request, create_facet_query, create_doi_aggregate, create_title_query, \
3637
create_identifier_query, create_pennsieve_identifier_query, create_field_query, create_request_body_for_curies, create_onto_term_query, \
@@ -55,6 +56,7 @@
5556
app = Flask(__name__)
5657
# set environment variable
5758
app.config["ENV"] = Config.DEPLOY_ENV
59+
cache = Cache(app, config={'CACHE_TYPE': 'SimpleCache', 'CACHE_DEFAULT_TIMEOUT': 300})
5860

5961
CORS(app)
6062

@@ -893,8 +895,8 @@ def datasets_by_project_id(project_id):
893895
def get_featured_datasets_identifiers():
894896
return {'identifiers': get_featured_datasets()}
895897

896-
897898
@app.route("/get_featured_dataset", methods=["GET"])
899+
@cache.cached(timeout=300)
898900
def get_featured_dataset():
899901
featured_dataset_id = get_featured_dataset_id_table_state(featuredDatasetIdSelectorTable)["featured_dataset_id"]
900902
if featured_dataset_id == -1:

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ oauth2client==4.1.3
3939
algoliasearch==2.6.2
4040
contentful==1.13.1
4141
contentful_management==2.11.0
42+
Flask-Caching==2.3.0

0 commit comments

Comments
 (0)