[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Replacing Controller's enable_caching constructor arg with setter



commit 27630c4d7f17052975238a0f7622ec3418bdbd5e
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Tue Mar 5 11:01:56 2013 -0800

    Replacing Controller's enable_caching constructor arg with setter
    
    It's clunky for cache toggling to be a constructor arg since most of our users
    will be using from_port() or from_socket_file() instead.
---
 stem/control.py                 |   17 +++++++++++++++--
 test/unit/control/controller.py |    2 +-
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index a342fd0..85b1c8e 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -42,6 +42,7 @@ providing its own for interacting at a higher level.
     |- remove_event_listener - removes a listener so it isn't notified of further events
     |
     |- is_caching_enabled - true if the controller has enabled caching
+    |- set_caching - enables or disables caching
     |- clear_cache - clears any cached results
     |
     |- load_conf - loads configuration information as if it was in the torrc
@@ -659,10 +660,10 @@ class Controller(BaseController):
   from_port = staticmethod(from_port)
   from_socket_file = staticmethod(from_socket_file)
 
-  def __init__(self, control_socket, enable_caching = True):
+  def __init__(self, control_socket):
     super(Controller, self).__init__(control_socket)
 
-    self._is_caching_enabled = enable_caching
+    self._is_caching_enabled = True
     self._request_cache = {}
 
     # mapping of event types to their listeners
@@ -1585,6 +1586,18 @@ class Controller(BaseController):
 
     return self._is_caching_enabled
 
+  def set_caching(self, enabled):
+    """
+    Enables or disables caching of information retrieved from tor.
+
+    :param bool enabled: **True** to enable caching, **False** to disable it
+    """
+
+    self._is_caching_enabled = enabled
+
+    if not self._is_caching_enabled:
+      self.clear_cache()
+
   def clear_cache(self):
     """
     Drops any cached results.
diff --git a/test/unit/control/controller.py b/test/unit/control/controller.py
index bf910f2..746d9ce 100644
--- a/test/unit/control/controller.py
+++ b/test/unit/control/controller.py
@@ -20,7 +20,7 @@ class TestControl(unittest.TestCase):
     socket = stem.socket.ControlSocket()
 
     mocking.mock_method(Controller, "add_event_listener", mocking.no_op())
-    self.controller = Controller(socket, enable_caching = True)
+    self.controller = Controller(socket)
     mocking.revert_mocking()
 
   def tearDown(self):



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits