Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: more debugging of memcached client #685

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions enterprise_catalog/apps/api_client/discovery_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,16 @@ def _get_catalog_query_metadata(self, catalog_query):
# 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
# Access and invalidate the @cached_property _cache attribute.
# This will force the django memcached.py backend to recompute
# a pymemcache client for us with updated options.
# See Django's `BaseMemcachedCache` implementation.

# pylint: disable=protected-access
_ = cache._cache
del cache._cache
cache._options['ignore_exc'] = False
LOGGER.info('Cache instance options %s', cache._options)
cache_add_success = False
try:
cache_add_success = cache.add(
Expand All @@ -78,10 +87,16 @@ def _get_catalog_query_metadata(self, catalog_query):
settings.DISCOVERY_CATALOG_QUERY_CACHE_TIMEOUT,
)
except Exception as exc: # pylint: disable=broad-except
LOGGER.exception('Cache add fail %s', exc)
LOGGER.exception('Cache add did not succeed %s', exc)
finally:
if hasattr(cache, '_options'):
cache._options['ignore_exc'] = True # pylint: disable=protected-access
# pylint: disable=protected-access
cache._options['ignore_exc'] = True
# Access and invalidate as above, so the next
# user of django.core.cache.cache has the expected
# set of options from Django settings.
_ = cache._cache
del cache._cache

if cache_add_success:
LOGGER.info(
Expand Down