Skip to content

Commit 79a8702

Browse files
authored
Merge pull request #2831 from britneywwc/discourse-cache
refactor: reuse single discourse cache across API instances
2 parents 0562734 + 65596b5 commit 79a8702

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

webapp/app.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
search_all_docs,
9494
)
9595
from webapp import ubuntu_pro_description as _upsd
96+
from webapp.utils.constants import CACHE_TTL
9697

9798
logger = logging.getLogger(__name__)
9899

@@ -146,6 +147,7 @@
146147
app.jinja_loader = loader
147148
search_session = get_requests_session()
148149
discourse_session = get_requests_session()
150+
ubuntu_discourse_cache = ResponseCache(ttl=CACHE_TTL)
149151

150152
app.register_blueprint(application_bp, url_prefix="/careers/application")
151153

@@ -298,9 +300,6 @@ def search_docs():
298300
)
299301

300302

301-
CACHE_TTL = 60 * 60 # 1 hour cache
302-
303-
304303
@app.route("/juju/latest.json")
305304
@cross_origin()
306305
@cached(cache=TTLCache(maxsize=128, ttl=CACHE_TTL))
@@ -1135,7 +1134,7 @@ def allow_src(tag, name, value):
11351134
api=DiscourseAPI(
11361135
base_url="https://discourse.dqlite.io/",
11371136
session=discourse_session,
1138-
cache=ResponseCache(ttl=600),
1137+
cache=None,
11391138
),
11401139
index_topic_id=34,
11411140
url_prefix="/dqlite/docs",
@@ -1169,7 +1168,7 @@ def allow_src(tag, name, value):
11691168
base_url="https://discourse.maas.io/",
11701169
session=discourse_session,
11711170
get_topics_query_id=2,
1172-
cache=ResponseCache(ttl=600),
1171+
cache=ubuntu_discourse_cache,
11731172
),
11741173
index_topic_id=6662,
11751174
url_prefix=maas_url_prefix,
@@ -1254,7 +1253,7 @@ def maas_docs_api():
12541253
api_key=MAAS_DISCOURSE_API_KEY,
12551254
api_username=MAAS_DISCOURSE_API_USERNAME,
12561255
get_topics_query_id=2,
1257-
cache=ResponseCache(ttl=600),
1256+
cache=ubuntu_discourse_cache,
12581257
),
12591258
index_topic_id=1289,
12601259
url_prefix="/maas/tutorials",
@@ -1518,7 +1517,7 @@ def cred_exam_content(**_):
15181517
get_topics_query_id=14,
15191518
api_key=DISCOURSE_API_KEY,
15201519
api_username=DISCOURSE_API_USERNAME,
1521-
cache=ResponseCache(ttl=600),
1520+
cache=ubuntu_discourse_cache,
15221521
)
15231522
engage_pages = EngagePages(
15241523
api=engage_pages_discourse_api,
@@ -1548,7 +1547,7 @@ def cred_exam_content(**_):
15481547
session=search_session,
15491548
api_key=DISCOURSE_API_KEY,
15501549
api_username=DISCOURSE_API_USERNAME,
1551-
cache=ResponseCache(ttl=600),
1550+
cache=ubuntu_discourse_cache,
15521551
)
15531552

15541553

@@ -1584,7 +1583,7 @@ def cred_exam_content(**_):
15841583
api=DiscourseAPI(
15851584
base_url="https://discuss.kubernetes.io/",
15861585
session=get_requests_session(),
1587-
cache=ResponseCache(ttl=600),
1586+
cache=None,
15881587
),
15891588
index_topic_id=11243,
15901589
url_prefix=microk8s_url_prefix,

webapp/utils/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
# and this is undesired. We are tracking the req ID here so that
66
# it can be hidden on the Candidate Dash.
77
SECOND_LOOK_REQ_ID = 3013911
8+
9+
# Default time-to-live for ResponseCache instances, in seconds (1 hour)
10+
CACHE_TTL = 60 * 60

0 commit comments

Comments
 (0)