From 3a0bacde3a37027d7e38bef162a74c42f2944ca3 Mon Sep 17 00:00:00 2001 From: Min RK Date: Mon, 12 Nov 2018 12:56:22 +0100 Subject: [PATCH] HubAuth: allow caching None responses when a token doesn't identify a user, the response is None. These results are cached, but the cache checked for `is None`, causing failed-auth responses to effectively not be cached. --- jupyterhub/services/auth.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/jupyterhub/services/auth.py b/jupyterhub/services/auth.py index ef80799f..4ce9ed84 100644 --- a/jupyterhub/services/auth.py +++ b/jupyterhub/services/auth.py @@ -277,11 +277,10 @@ class HubAuth(SingletonConfigurable): if cache_key is None: raise ValueError("cache_key is required when using cache") # check for a cached reply, so we don't check with the Hub if we don't have to - cached = self.cache.get(cache_key) - if cached is not None: - return cached - else: - app_log.debug("Cache miss: %s" % cache_key) + try: + return self.cache[cache_key] + except KeyError: + app_log.debug("HubAuth cache miss: %s", cache_key) data = self._api_request('GET', url, allow_404=True) if data is None: