Skip to content

Commit

Permalink
fix: don't log useless/opaque cache keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveagent57 committed Jul 31, 2023
1 parent dc9fa89 commit f572f89
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ def get_and_cache_content_metadata(enterprise_customer_uuid, content_key, timeou
cache_key = versioned_cache_key('get_subsidy_content_metadata', enterprise_customer_uuid, content_key)
cached_response = TieredCache.get_cached_response(cache_key)
if cached_response.is_found:
logger.info('[METADATA CACHE HIT] for key %s', cache_key)
return cached_response.value

logger.info('[METADATA CACHE MISS] for key %s', cache_key)

client = get_versioned_subsidy_client()
try:
metadata = client.get_subsidy_content_data(
Expand All @@ -42,8 +39,12 @@ def get_and_cache_content_metadata(enterprise_customer_uuid, content_key, timeou
except HTTPError as exc:
raise exc

logger.info(
'Fetched content metadata for customer %s and content_key %s',
enterprise_customer_uuid,
content_key,
)
TieredCache.set_all_tiers(cache_key, metadata, timeout or DEFAULT_CACHE_TIMEOUT)
logger.info('[METADATA CACHE SET] for key = %s, value = %s', cache_key, metadata)
return metadata


Expand All @@ -56,10 +57,8 @@ def get_and_cache_catalog_contains_content(enterprise_catalog_uuid, content_key,
cache_key = versioned_cache_key('contains_content_key', enterprise_catalog_uuid, content_key)
cached_response = TieredCache.get_cached_response(cache_key)
if cached_response.is_found:
logger.info('[CATALOG INCLUSION CACHE HIT] for key %s', cache_key)
return cached_response.value

logger.info('[CATALOG INCLUSION CACHE MISS] for key %s', cache_key)
try:
result = EnterpriseCatalogApiClient().contains_content_items(
enterprise_catalog_uuid,
Expand All @@ -68,6 +67,11 @@ def get_and_cache_catalog_contains_content(enterprise_catalog_uuid, content_key,
except HTTPError as exc:
raise exc

logger.info(
'Fetched catalog inclusion for catalog %s and content_key %s. Result = %s',
enterprise_catalog_uuid,
content_key,
result,
)
TieredCache.set_all_tiers(cache_key, result, timeout or DEFAULT_CACHE_TIMEOUT)
logger.info('[CATALOG INCLUSION CACHE SET] for key = %s, value = %s', cache_key, result)
return result
9 changes: 6 additions & 3 deletions enterprise_access/apps/subsidy_access_policy/subsidy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ def get_and_cache_transactions_for_learner(subsidy_uuid, lms_user_id):
cache_key = learner_transaction_cache_key(subsidy_uuid, lms_user_id)
cached_response = request_cache().get_cached_response(cache_key)
if cached_response.is_found:
logger.info('[LEARNER TRANSACTIONS CACHE HIT] for key %s', cache_key)
return cached_response.value

logger.info('[LEARNER TRANSACTIONS CACHE MISS] for key %s', cache_key)
client = get_versioned_subsidy_client()
response_payload = client.list_subsidy_transactions(
subsidy_uuid=subsidy_uuid,
Expand All @@ -54,7 +52,12 @@ def get_and_cache_transactions_for_learner(subsidy_uuid, lms_user_id):
result['transactions'].extend(next_response['results'])
next_page = next_response.get('next')

logger.info('[LEARNER TRANSACTIONS CACHE SET] for key %s', cache_key)
logger.info(
'Fetched transactions for subsidy %s and lms_user_id %s. Number transactions = %s',
subsidy_uuid,
lms_user_id,
len(result['transactions']),
)
request_cache().set(cache_key, result)
return result

Expand Down

0 comments on commit f572f89

Please sign in to comment.