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

[tor-commits] [stem/master] Caching parsed controller version



commit 2a34547cc6dc157617c4a485d7e9e41816d46e66
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Aug 6 08:45:07 2012 -0700

    Caching parsed controller version
    
    Our controller version is something that we'll frequently look up. There's no
    reason to leave it uncached.
---
 stem/control.py |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index 673261c..6fed090 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -627,7 +627,13 @@ class Controller(BaseController):
       * ValueError if unable to parse the version
     """
     
-    return stem.version.Version(self.get_info("version"))
+    if not self.is_caching_enabled():
+      return stem.version.Version(self.get_info("version"))
+    elif not "version" in self._request_cache:
+      version = stem.version.Version(self.get_info("version"))
+      self._request_cache["version"] = version
+    
+    return self._request_cache["version"]
   
   def authenticate(self, *args, **kwargs):
     """



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