
commit c20f7fd6454f08d2525e2d38f1c2069c7027713e Author: Damian Johnson <atagar@torproject.org> Date: Sat Sep 23 19:00:33 2017 -0700 Simpler cache fetching for single values Usually when we reference the cache it's for just a single value. No need for an intermediate hash and dict. --- stem/control.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/stem/control.py b/stem/control.py index 796aa016..ce339da9 100644 --- a/stem/control.py +++ b/stem/control.py @@ -3064,7 +3064,12 @@ class Controller(BaseController): :returns: cached value corresponding to key or **None** if the key wasn't found """ - return self._get_cache_map([param], namespace).get(param, None) + with self._cache_lock: + if not self.is_caching_enabled(): + return None + + cache_key = '%s.%s' % (namespace, param) if namespace else param + return self._request_cache.get(cache_key, None) def _get_cache_map(self, params, namespace = None): """ @@ -3081,10 +3086,7 @@ class Controller(BaseController): if self.is_caching_enabled(): for param in params: - if namespace: - cache_key = '%s.%s' % (namespace, param) - else: - cache_key = param + cache_key = '%s.%s' % (namespace, param) if namespace else param if cache_key in self._request_cache: cached_values[param] = self._request_cache[cache_key]