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

atagar at torproject.org atagar at torproject.org
Wed Aug 22 01:12:46 UTC 2012


commit 2a34547cc6dc157617c4a485d7e9e41816d46e66
Author: Damian Johnson <atagar at torproject.org>
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):
     """





More information about the tor-commits mailing list