public class LruTaxonomyWriterCache extends Object implements TaxonomyWriterCache
TaxonomyWriterCache
- good choice for huge taxonomies.Modifier and Type | Class and Description |
---|---|
static class |
LruTaxonomyWriterCache.LRUType
Determines cache type.
|
Constructor and Description |
---|
LruTaxonomyWriterCache(int cacheSize)
Creates this with
LruTaxonomyWriterCache.LRUType.LRU_STRING method. |
LruTaxonomyWriterCache(int cacheSize,
LruTaxonomyWriterCache.LRUType lruType)
Creates this with the specified method.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears the content of the cache.
|
void |
close()
Let go of whatever resources the cache is holding.
|
int |
get(FacetLabel categoryPath)
Lookup a category in the cache, returning its ordinal, or a negative
number if the category is not in the cache.
|
boolean |
isFull()
Returns true if the cache is full, such that the next
TaxonomyWriterCache.put(org.apache.lucene.facet.taxonomy.FacetLabel, int) will
evict entries from it, false otherwise. |
boolean |
put(FacetLabel categoryPath,
int ordinal)
Add a category to the cache, with the given ordinal as the value.
|
int |
size()
How many labels are currently stored in the cache.
|
public LruTaxonomyWriterCache(int cacheSize)
LruTaxonomyWriterCache.LRUType.LRU_STRING
method.public LruTaxonomyWriterCache(int cacheSize, LruTaxonomyWriterCache.LRUType lruType)
public boolean isFull()
TaxonomyWriterCache
TaxonomyWriterCache.put(org.apache.lucene.facet.taxonomy.FacetLabel, int)
will
evict entries from it, false otherwise.isFull
in interface TaxonomyWriterCache
public void clear()
TaxonomyWriterCache
TaxonomyWriterCache.close()
, the caller can
assume that the cache is still operable after this method returns.clear
in interface TaxonomyWriterCache
public void close()
TaxonomyWriterCache
close
in interface TaxonomyWriterCache
public int size()
TaxonomyWriterCache
size
in interface TaxonomyWriterCache
public int get(FacetLabel categoryPath)
TaxonomyWriterCache
It is up to the caller to remember what a negative response means: If the caller knows the cache is complete (it was initially fed with all the categories, and since then put() never returned true) it means the category does not exist. Otherwise, the category might still exist, but just be missing from the cache.
get
in interface TaxonomyWriterCache
public boolean put(FacetLabel categoryPath, int ordinal)
TaxonomyWriterCache
If the implementation keeps only a partial cache (e.g., an LRU cache)
and finds that its cache is full, it should clear up part of the cache
and return true
. Otherwise, it should return
false
.
The reason why the caller needs to know if part of the cache was cleared is that in that case it will have to commit its on-disk index (so that all the latest category additions can be searched on disk, if we can't rely on the cache to contain them).
Ordinals should be non-negative. Currently there is no defined way to specify that a cache should remember a category does NOT exist. It doesn't really matter, because normally the next thing we do after finding that a category does not exist is to add it.
put
in interface TaxonomyWriterCache
Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.