You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2021/12/13 11:43:00 UTC
[uima-ruta] 01/01: [UIMA-6399] RutaPatternCache prevents CPEEngine from terminating
This is an automated email from the ASF dual-hosted git repository.
rec pushed a commit to branch bugfix/UIMA-6399-RutaPatternCache-prevents-CPEEngine-from-terminating
in repository https://gitbox.apache.org/repos/asf/uima-ruta.git
commit 5f2f51ec6fd77439f2872e61b10b12720c8a83f5
Author: Richard Eckart de Castilho <re...@apache.org>
AuthorDate: Mon Dec 13 12:42:46 2021 +0100
[UIMA-6399] RutaPatternCache prevents CPEEngine from terminating
- Removed time-based clearing of the RutaPatternCache to avoid cleanup threads being spawned
- Added a way to configure the pattern cache size from a system property
---
.../apache/uima/ruta/cache/RutaPatternCache.java | 25 +++++++++++-----------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/ruta-core/src/main/java/org/apache/uima/ruta/cache/RutaPatternCache.java b/ruta-core/src/main/java/org/apache/uima/ruta/cache/RutaPatternCache.java
index 15172a2..f3d1b77 100644
--- a/ruta-core/src/main/java/org/apache/uima/ruta/cache/RutaPatternCache.java
+++ b/ruta-core/src/main/java/org/apache/uima/ruta/cache/RutaPatternCache.java
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,7 +25,6 @@ import static java.util.regex.Pattern.UNICODE_CASE;
import java.util.Collections;
import java.util.Map;
-import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import com.github.benmanes.caffeine.cache.Caffeine;
@@ -37,14 +36,17 @@ import com.github.benmanes.caffeine.cache.LoadingCache;
*/
public class RutaPatternCache {
- private static final LoadingCache<PatternCacheKey, Pattern> CACHE = Caffeine.newBuilder()
- .expireAfterAccess(6, TimeUnit.HOURS)
- .expireAfterWrite(12, TimeUnit.HOURS)
- .maximumSize(10_000)
+ private static final String PROP_RUTA_PATTERN_CACHE_SIZE = "uima.ruta.pattern_cache_size";
+
+ private static final int RUTA_PATTERN_CACHE_SIZE = Integer
+ .parseInt(System.getProperty(PROP_RUTA_PATTERN_CACHE_SIZE, "10000"));
+
+ private static final LoadingCache<PatternCacheKey, Pattern> CACHE = Caffeine.newBuilder() //
+ .maximumSize(RUTA_PATTERN_CACHE_SIZE) //
.build(k -> createPattern(k));
/**
- *
+ *
* @param patternString
* regular expression as a string
* @param ignore
@@ -54,16 +56,16 @@ public class RutaPatternCache {
public static Pattern getPattern(String patternString, boolean ignore) {
int flags = MULTILINE | DOTALL;
-
+
if (ignore) {
flags |= CASE_INSENSITIVE | UNICODE_CASE;
}
-
+
return CACHE.get(new PatternCacheKey(patternString, flags));
}
/**
- *
+ *
* @param patternString
* regular expression as a string
* @param flags
@@ -93,5 +95,4 @@ public class RutaPatternCache {
CACHE.invalidateAll();
CACHE.cleanUp();
}
-
}