Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions apps/application/flow/compare/regex_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
from .compare import Compare
from common.cache.mem_cache import MemCache


match_cache = MemCache('regex', {
'TIMEOUT': 3600, # 缓存有效期为 1 小时
'TIMEOUT': 3600, # 缓存有效期为 1 小时
'OPTIONS': {
'MAX_ENTRIES': 500, # 最多缓存 500 个条目
'CULL_FREQUENCY': 10, # 达到上限时,删除约 1/10 的缓存
'MAX_ENTRIES': 500, # 最多缓存 500 个条目
'CULL_FREQUENCY': 10, # 达到上限时,删除约 1/10 的缓存
},
})


def compile_and_cache(regex):
match = match_cache.get(regex)
if not match:
match = re.compile(regex).match
match = re.compile(regex).fullmatch
match_cache.set(regex, match)
return match


class RegexCompare(Compare):

def compare(self, source_value, compare, target_value):
Expand Down
Loading