Get a compiled regular expression object based on pattern and cache it when it is not in the cache already
(self, pattern)
| 279 | del self.cache[patterns[idx][2]] |
| 280 | |
| 281 | def get(self, pattern): |
| 282 | """ |
| 283 | Get a compiled regular expression object based on pattern and |
| 284 | cache it when it is not in the cache already |
| 285 | """ |
| 286 | try: |
| 287 | self.cache[pattern][0] += 1 |
| 288 | return self.cache[pattern][1] |
| 289 | except KeyError: |
| 290 | pass |
| 291 | if len(self.cache) > self.size: |
| 292 | self.sweep() |
| 293 | regex = re.compile(f"{self.prepend}{pattern}{self.append}") |
| 294 | self.cache[pattern] = [1, regex, pattern, time.time()] |
| 295 | return regex |
| 296 | |
| 297 | |
| 298 | class ContextCache: |