aboutsummaryrefslogtreecommitdiff
path: root/IP2Location_cached.py
diff options
context:
space:
mode:
authorPaul Sokolovsky <paul.sokolovsky@linaro.org>2014-03-27 22:36:42 +0200
committerPaul Sokolovsky <paul.sokolovsky@linaro.org>2014-03-28 01:37:28 +0200
commitfb5683f0ebbe6e67c353518366bac81848c6c9b9 (patch)
treed4e37181a99dfa4f6a03c8fb9f6645a2972ebe25 /IP2Location_cached.py
parent51a05a651db7f90602ea1db20166ddd591b71cc1 (diff)
IP2Location_cached: Cache also on get_all() level.
Change-Id: I7f6d7a1934175d6bca08959cb05951141583fc81
Diffstat (limited to 'IP2Location_cached.py')
-rw-r--r--IP2Location_cached.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/IP2Location_cached.py b/IP2Location_cached.py
index 948213d..e31cbff 100644
--- a/IP2Location_cached.py
+++ b/IP2Location_cached.py
@@ -75,6 +75,7 @@ class IP2Location(object):
self._index = None
self._rec_cache = {}
self._rec_hits = 0
+ self._ip_cache = {}
def get_country_short(self, ip):
''' Get country_short '''
@@ -158,7 +159,11 @@ class IP2Location(object):
return rec and rec.usage_type
def get_all(self, ip):
''' Get all '''
- return self._get_record(ip)
+ if ip in self._ip_cache:
+ return self._ip_cache[ip]
+ r = self._get_record(ip)
+ self._ip_cache[ip] = r
+ return r
def find(self, ip):
''' Find IP record '''