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

[tor-commits] [stem/master] Add function for single param cache query



commit f208da6d4ca07ee4d241bd67085ba331bcc07d4b
Author: Akshit Khurana <axitkhurana@xxxxxxxxx>
Date:   Sun May 12 03:03:50 2013 +0530

    Add function for single param cache query
    
    Separate functions for single param cache query and multiple params.
     * get_conf : takes single param, returns value
     * get_conf_map: takes list of params, return dict
---
 stem/control.py |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index 304a808..71f790e 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -756,7 +756,7 @@ class Controller(BaseController):
 
     # check for cached results
     from_cache = [param.lower() for param in params]
-    cached_results = self._get_cache(from_cache, "getinfo")
+    cached_results = self._get_cache_map(from_cache, "getinfo")
 
     reply = {}
     for key in cached_results.keys():
@@ -849,7 +849,7 @@ class Controller(BaseController):
       if not self.is_caching_enabled():
         return stem.version.Version(self.get_info("version"))
       else:
-        version = self._get_cache(["version"]).get("version", None)
+        version = self._get_cache("version")
 
         if not version:
           version = stem.version.Version(self.get_info("version"))
@@ -880,8 +880,7 @@ class Controller(BaseController):
     """
     with self._msg_lock:
       try:
-        config_policy = self._get_cache(["exit_policy"]).get("exit_policy",
-                                                             None)
+        config_policy = self._get_cache("exit_policy")
         if not config_policy:
           policy = []
 
@@ -1330,7 +1329,7 @@ class Controller(BaseController):
 
     # check for cached results
     from_cache = [param.lower() for param in lookup_params]
-    cached_results = self._get_cache(from_cache, "getconf")
+    cached_results = self._get_cache_map(from_cache, "getconf")
 
     reply = {}
     for key in cached_results.keys():
@@ -1597,7 +1596,19 @@ class Controller(BaseController):
         if not response.is_ok():
           raise stem.ProtocolError("SETEVENTS received unexpected response\n%s" % response)
 
-  def _get_cache(self, params, func=None):
+  def _get_cache(self, param, func=None):
+    """
+    Queries cache for a configuration option.
+
+    :param str param: key to be queried in cache
+    :param str func: function prefix to keys
+
+    :returns: cached value corresponding to key or None if key wasn't found
+    """
+
+    return self._get_cache_map([param], func).get(param, None)
+
+  def _get_cache_map(self, params, func=None):
     """
     Queries multiple configuration options in cache atomically, returning a
     mapping of those options to their values.



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