2020from lib .core .convert import getBytes
2121from lib .core .convert import getUnicode
2222from lib .core .data import logger
23+ from lib .core .datatype import LRUDict
2324from lib .core .exception import SqlmapConnectionException
2425from lib .core .settings import HASHDB_END_TRANSACTION_RETRIES
2526from lib .core .settings import HASHDB_FLUSH_RETRIES
@@ -33,6 +34,7 @@ class HashDB(object):
3334 def __init__ (self , filepath ):
3435 self .filepath = filepath
3536 self ._write_cache = {}
37+ self ._read_cache = LRUDict (capacity = 100 )
3638 self ._cache_lock = threading .Lock ()
3739 self ._connections = []
3840 self ._last_flush_time = time .time ()
@@ -91,6 +93,10 @@ def retrieve(self, key, unserialize=False):
9193 if key and (self ._write_cache or self ._connections or os .path .isfile (self .filepath )):
9294 hash_ = HashDB .hashKey (key )
9395 retVal = self ._write_cache .get (hash_ )
96+
97+ if retVal is None :
98+ retVal = self ._read_cache .get (hash_ )
99+
94100 if not retVal :
95101 for _ in xrange (HASHDB_RETRIEVE_RETRIES ):
96102 try :
@@ -111,6 +117,9 @@ def retrieve(self, key, unserialize=False):
111117
112118 time .sleep (1 )
113119
120+ if retVal is not None :
121+ self ._read_cache [hash_ ] = retVal
122+
114123 if retVal and unserialize :
115124 try :
116125 retVal = unserializeObject (retVal )
@@ -126,7 +135,7 @@ def write(self, key, value, serialize=False):
126135 if key :
127136 hash_ = HashDB .hashKey (key )
128137 with self ._cache_lock :
129- self ._write_cache [hash_ ] = getUnicode (value ) if not serialize else serializeObject (value )
138+ self ._write_cache [hash_ ] = self . _read_cache [ hash_ ] = getUnicode (value ) if not serialize else serializeObject (value )
130139 cache_size = len (self ._write_cache )
131140 time_since_flush = time .time () - self ._last_flush_time
132141
0 commit comments