

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I clear the regular expression cache in Python?
Presently, when regular expressions are compiled, the result is cached so that if the same regex is compiled again, it is retrieved from the cache and no extra effort is required. This cache supports up to 100 entries. Once the 100th entry is reached, the cache is cleared and a new compile must occur.
The objective of caching is to decrease the average call time of the function. The overhead associated with keeping more information in _cache and paring it instead of clearing it would increase that average call time. The _cache.clear() call will complete quickly, and even though cache is lost this is preferable over maintaining a cache state and having the overhead of removing individual elements from the cache when the limit is reached.
There are a few things to think about when calculating the cache efficiency −
Average call time on cache hits (very short)
Average call time on cache misses (longer)
Frequency of cache hits (fairly uncommon)
Call time when cache is cleared or pruned (fairly uncommon)
The regular expression cache is cleared using _cache.clear() when it reaches _MAXCACHE of entries.
- Related Questions & Answers
- How do I clear the usage of setInterval()?
- How do we use Python Regular Expression named groups?
- How do we use re.finditer() method in Python regular expression?
- How do I clear the cin buffer in C++?
- Why do we use re.compile() method in Python regular expression?
- How can I find all matches to a regular expression in Python?
- How do you validate a URL with a regular expression in Python?
- How do we find the exact positions of each match in Python regular expression?
- Regular Expression Modifiers in Python
- Regular Expression Patterns in Python
- Regular Expression Examples in Python
- Regular Expression Matching in Python
- How regular expression modifiers work in Python?
- How regular expression grouping works in Python?
- How regular expression alternatives work in Python?