CACHED_REGEXES_MAX_SIZE, thanks Anthony

This commit is contained in:
mdipierro
2012-09-03 08:09:49 -05:00
parent 7b24ce3f41
commit 90c0e0ff7e
2 changed files with 4 additions and 1 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.0.6 (2012-09-02 22:34:20) stable
Version 2.0.6 (2012-09-03 08:09:45) stable
+3
View File
@@ -92,11 +92,14 @@ _TEST()
"""
CACHED_REGEXES = {}
CACHED_REGEXES_MAX_SIZE = 1000
def re_compile(regex):
try:
return CACHED_REGEXES[regex]
except KeyError:
if len(CACHED_REGEXES) >= CACHED_REGEXES_MAX_SIZE:
CACHED_REGEXES.clear()
compiled_regex = CACHED_REGEXES[regex] = re.compile(regex)
return compiled_regex