Package org.languagetool
Class ResultCache
- java.lang.Object
-
- org.languagetool.ResultCache
-
public class ResultCache extends java.lang.Object
A cache to speed up text checking for use cases where sentences are checked more than once. This typically happens when using LT as a server and texts get re-checked after corrections have been applied for some sentences. Use the same cache object for allJLanguageTool
objects only if the JLanguageTool objects all use the same rules. For example, if you callJLanguageTool.addRule()
in different ways for the different instances that you use the same cache for, the cache will return invalid results. Using a cache with bitext rules isn't supported either. It is okay however, to use the same cache forJLanguageTool
objects with different languages, as cached results are not used for a different language.- Since:
- 3.7
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
ResultCache.MatchesWeigher
(package private) class
ResultCache.SentenceWeigher
-
Field Summary
Fields Modifier and Type Field Description private com.google.common.cache.Cache<InputSentence,java.util.List<RuleMatch>>
matchesCache
private com.google.common.cache.Cache<SimpleInputSentence,AnalyzedSentence>
sentenceCache
-
Constructor Summary
Constructors Constructor Description ResultCache(long maxSize)
Create a cache that expires items 5 minutes after the latest read access.ResultCache(long maxSize, long expireAfter, java.util.concurrent.TimeUnit timeUnit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<RuleMatch>
getIfPresent(InputSentence key)
AnalyzedSentence
getIfPresent(SimpleInputSentence key)
com.google.common.cache.Cache<InputSentence,java.util.List<RuleMatch>>
getMatchesCache()
com.google.common.cache.Cache<SimpleInputSentence,AnalyzedSentence>
getSentenceCache()
long
hitCount()
double
hitRate()
void
put(InputSentence key, java.util.List<RuleMatch> sentenceMatches)
void
put(SimpleInputSentence key, AnalyzedSentence aSentence)
double
requestCount()
-
-
-
Field Detail
-
matchesCache
private final com.google.common.cache.Cache<InputSentence,java.util.List<RuleMatch>> matchesCache
-
sentenceCache
private final com.google.common.cache.Cache<SimpleInputSentence,AnalyzedSentence> sentenceCache
-
-
Constructor Detail
-
ResultCache
public ResultCache(long maxSize)
Create a cache that expires items 5 minutes after the latest read access.- Parameters:
maxSize
- maximum cache size in number of sentences
-
ResultCache
public ResultCache(long maxSize, long expireAfter, java.util.concurrent.TimeUnit timeUnit)
- Parameters:
maxSize
- maximum cache size in number of sentencesexpireAfter
- time to expire sentences from the cache after last read access
-
-
Method Detail
-
hitRate
public double hitRate()
-
requestCount
public double requestCount()
-
hitCount
public long hitCount()
-
getIfPresent
public java.util.List<RuleMatch> getIfPresent(InputSentence key)
-
getIfPresent
public AnalyzedSentence getIfPresent(SimpleInputSentence key)
-
put
public void put(InputSentence key, java.util.List<RuleMatch> sentenceMatches)
-
put
public void put(SimpleInputSentence key, AnalyzedSentence aSentence)
-
getMatchesCache
public com.google.common.cache.Cache<InputSentence,java.util.List<RuleMatch>> getMatchesCache()
- Since:
- 4.1
-
getSentenceCache
public com.google.common.cache.Cache<SimpleInputSentence,AnalyzedSentence> getSentenceCache()
- Since:
- 4.1
-
-