Skip to content

Commit d57d397

Browse files
LRU cache
1 parent ed48ab8 commit d57d397

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Lib/encodings/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ def search_function(encoding):
111111
mod = None
112112

113113
if mod is None:
114-
if len(_cache) < _MAXCACHE:
115-
_cache[encoding] = None
114+
if len(_cache) >= _MAXCACHE:
115+
_cache.clear()
116+
_cache[encoding] = None
116117
return None
117118

118119
# Now ask the module for the registry entry
@@ -133,6 +134,8 @@ def search_function(encoding):
133134
entry = codecs.CodecInfo(*entry)
134135

135136
# Cache the codec registry entry
137+
if len(_cache) >= _MAXCACHE:
138+
_cache.clear()
136139
_cache[encoding] = entry
137140

138141
# Register its aliases (without overwriting previously registered

0 commit comments

Comments
 (0)