Skip to content

Commit

Permalink
fix: add more memcache debugging to discovery cache client
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveagent57 committed Sep 29, 2023
1 parent 9b3c882 commit 8a7ca48
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion enterprise_catalog/apps/api_client/discovery_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,27 @@ def _get_catalog_query_metadata(self, catalog_query):
catalog_query_data = client.get_metadata_by_query(catalog_query)
if not catalog_query_data:
catalog_query_data = []

# cache.add() will not attempt to update the cache if the key specified is already present
# this is fine here, because we know we just encountered a cache miss on our key.
# add() returns a boolean letting us know if it stored anything in the cache
cache_add_success = cache.add(cache_key, catalog_query_data, settings.DISCOVERY_CATALOG_QUERY_CACHE_TIMEOUT)
# Debugging: force ignore_exc off to see what exception is getting raise
# on the cache adds.
if hasattr(cache, '_options'):
cache._options['ignore_exc'] = False # pylint: disable=protected-access

Check warning on line 72 in enterprise_catalog/apps/api_client/discovery_cache.py

View check run for this annotation

Codecov / codecov/patch

enterprise_catalog/apps/api_client/discovery_cache.py#L72

Added line #L72 was not covered by tests
cache_add_success = False
try:
cache_add_success = cache.add(
cache_key,
catalog_query_data,
settings.DISCOVERY_CATALOG_QUERY_CACHE_TIMEOUT,
)
except Exception as exc: # pylint: disable=broad-except
LOGGER.exception('Cache add fail %s', exc)

Check warning on line 81 in enterprise_catalog/apps/api_client/discovery_cache.py

View check run for this annotation

Codecov / codecov/patch

enterprise_catalog/apps/api_client/discovery_cache.py#L80-L81

Added lines #L80 - L81 were not covered by tests
finally:
if hasattr(cache, '_options'):
cache._options['ignore_exc'] = True # pylint: disable=protected-access

Check warning on line 84 in enterprise_catalog/apps/api_client/discovery_cache.py

View check run for this annotation

Codecov / codecov/patch

enterprise_catalog/apps/api_client/discovery_cache.py#L84

Added line #L84 was not covered by tests

if cache_add_success:
LOGGER.info(
'CatalogQueryDetails: CACHED CatalogQuery metadata with id %s for %s sec',
Expand Down

0 comments on commit 8a7ca48

Please sign in to comment.