kitsook/newsSum

GCP Python 3 caching

Closed this issue · 2 comments

The GCP Python 3 environment has removed support for memcache. Commented out the caching part.

newsSum/main.py

Lines 49 to 54 in a91908c

if thePath in allSources:
# try to retrieve from cache
# encodedArticles = memcache.get(thePath)
encodedArticles = None
if (encodedArticles == None):
articles.extend(allSources[thePath].get_articles())

Need to switch to external redis or Google Cloud Memorystore.

As an interim solution, set http headers and let browsers cache the result:

newsSum/main.py

Lines 63 to 67 in 9540662

# since we don't have memcache in GCP py3, tell browsers to cache everything to minimize our traffic
@app.after_request
def add_header(response):
response.cache_control.max_age = 300
return response

Set cache-control header to public with max-age to have browsers and any cache-capable servers along the path to cache the result.