Fixed #109 : Mix python and concept. List comprehension
Fixed #110 : SheerkaDebugManager: add list_debug_settings Fixed #111 : SheerkaDebugManager: Implement ListDebugLogger Fixed #112 : SyaNodeParser: rewrite this parser Fixed #113 : Sheerka.: Add enable_parser_caching to disable parsers caching Fixed #114 : SyaNodeParser : Implement fast cache to resolve unrecognized tokens requests Fixed #115 : BnfNodeParser : Implement fast cache to resolve unrecognized tokens requests Fixed #116 : SequenceNodeParser : Implement fast cache to resolve unrecognized tokens requests Fixed #117 : ResolveMultiplePluralAmbiguityEvaluator: Resolve Multiple plural ambiguity
This commit is contained in:
Vendored
+5
-1
@@ -11,6 +11,7 @@ class FastCache:
|
||||
self.cache = {}
|
||||
self.lru = []
|
||||
self.default = default
|
||||
self.calls = {}
|
||||
|
||||
def __contains__(self, item):
|
||||
return self.has(item)
|
||||
@@ -24,13 +25,16 @@ class FastCache:
|
||||
|
||||
self.cache[key] = value
|
||||
self.lru.append(key)
|
||||
self.calls[key] = 0
|
||||
|
||||
def has(self, key):
|
||||
return key in self.cache
|
||||
|
||||
def get(self, key):
|
||||
try:
|
||||
return self.cache[key]
|
||||
res = self.cache[key]
|
||||
self.calls[key] += 1
|
||||
return res
|
||||
except KeyError:
|
||||
if self.default:
|
||||
value = self.default(key)
|
||||
|
||||
Reference in New Issue
Block a user