Skip to content

Conversation

jg-rp
Copy link
Owner

@jg-rp jg-rp commented Aug 26, 2025

This PR adds an LRU cache and uses it to cache regex patterns for the match and search function extensions.

Previously we relied on the re module's internal cache. But since we now check patterns against I-Regexp (if it's installed) and map patterns from I-Regexp to Python re compatible patterns, we need our own cache.

Both jsonpath.function_extensions.Match and jsonpath.function_extensions.Search now also accept additional constructor arguments:

  • cache_capacity: The size of the regular expression cache.
  • debug: When True, raise an exception when regex pattern compilation fails. The default - as required by RFC 9535 - is False, which silently ignores bad patterns.
  • thread_safe: When True, use a ThreadSafeLRUCache instead of an instance of LRUCache.

@jg-rp jg-rp marked this pull request as ready for review August 26, 2025 16:06
@jg-rp jg-rp merged commit 863d47d into main Aug 27, 2025
26 checks passed
@jg-rp jg-rp deleted the regex-cache branch August 27, 2025 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant