[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Refactor cache invalidation resulting from config change into new method
commit fdd34f81b986fdb21e782993ca380d5e65036494
Author: Dave Rolek <dmr-x@xxxxxxxxxx>
Date: Mon May 14 16:20:49 2018 +0000
Refactor cache invalidation resulting from config change into new method
into: _confchanged_cache_invalidation()
Also use this for _confchanged_listener(), thereby likely fixing a few
bugs from the additional cache invalidation beyond exit_policy.
See #25821
---
stem/control.py | 41 ++++++++++++++++++++++++++++-------------
1 file changed, 28 insertions(+), 13 deletions(-)
diff --git a/stem/control.py b/stem/control.py
index c2467a53..b9534f31 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -1064,9 +1064,10 @@ class Controller(BaseController):
def _confchanged_listener(event):
if self.is_caching_enabled():
- self._set_cache(dict((k, None) for k in event.config), 'getconf')
+ to_cache = dict((k, None) for k in event.config)
+ self._set_cache(to_cache, 'getconf')
- self._set_cache({'exit_policy': None}) # numerous options can change our policy
+ self._confchanged_cache_invalidation(to_cache)
self.add_event_listener(_confchanged_listener, EventType.CONF_CHANGED)
@@ -2435,18 +2436,8 @@ class Controller(BaseController):
to_cache[param] = value
- if 'hidden' in param:
- self._set_cache({'hidden_service_conf': None})
-
- # reset any getinfo parameters that can be changed by a SETCONF
-
- self._set_cache(dict([(k.lower(), None) for k in CACHEABLE_GETINFO_PARAMS_UNTIL_SETCONF]), 'getinfo')
- self._set_cache(None, 'listeners')
-
self._set_cache(to_cache, 'getconf')
- self._set_cache({'get_custom_options': None})
-
- self._set_cache({'exit_policy': None}) # numerous options can change our policy
+ self._confchanged_cache_invalidation(dict(params))
else:
log.debug('%s (failed, code: %s, message: %s)' % (query, response.code, response.message))
immutable_params = [k for k, v in params if stem.util.str_tools._to_unicode(k).lower() in IMMUTABLE_CONFIG_OPTIONS]
@@ -3206,6 +3197,30 @@ class Controller(BaseController):
else:
self._request_cache[cache_key] = value
+ def _confchanged_cache_invalidation(self, params):
+ """
+ Drops dependent portions of the cache when configuration changes.
+
+ :param dict params: **dict** of 'config_key => value' pairs for configs
+ that changed. The entries' values are currently unused.
+ """
+
+ with self._cache_lock:
+ if not self.is_caching_enabled():
+ return
+
+ if any('hidden' in param.lower() for param in params.keys()):
+ self._set_cache({'hidden_service_conf': None})
+
+ # reset any getinfo parameters that can be changed by a SETCONF
+
+ self._set_cache(dict([(k.lower(), None) for k in CACHEABLE_GETINFO_PARAMS_UNTIL_SETCONF]), 'getinfo')
+ self._set_cache(None, 'listeners')
+
+ self._set_cache({'get_custom_options': None})
+
+ self._set_cache({'exit_policy': None}) # numerous options can change our policy
+
def is_caching_enabled(self):
"""
**True** if caching has been enabled, **False** otherwise.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits