Interface ITaxonomyWriterCache
ITaxonomyWriterCache is a relatively simple interface for a cache of category->ordinal mappings, used in ITaxonomyWriter implementations (such as DirectoryTaxonomyWriter).
It basically has Put(FacetLabel, int) methods for adding a mapping, and Get(FacetLabel) for looking a mapping up the cache. The cache does not guarantee to hold everything that has been put into it, and might in fact selectively delete some of the mappings (e.g., the ones least recently used). This means that if Get(FacetLabel) returns a negative response, it does not necessarily mean that the category doesn't exist - just that it is not in the cache. The caller can only infer that the category doesn't exist if it knows the cache to be complete (because all the categories were loaded into the cache, and since then no Put(FacetLabel, int) returned true).
However, if it does so, it should clear out large parts of the cache at once, because the user will typically need to work hard to recover from every cache cleanup (see Put(FacetLabel, int)'s return value).
NOTE: the cache may be accessed concurrently by multiple threads, therefore cache implementations should take this into consideration.
Note
This API is experimental and might change in incompatible ways in the next release.
Inherited Members
Namespace: Lucene.Net.Facet.Taxonomy.WriterCache
Assembly: Lucene.Net.Facet.dll
Syntax
public interface ITaxonomyWriterCache : IDisposable
Properties
IsFull
Returns true if the cache is full, such that the next Put(FacetLabel, int) will evict entries from it, false otherwise.
Declaration
bool IsFull { get; }
Property Value
Type | Description |
---|---|
bool |
Methods
Clear()
Clears the content of the cache. Unlike Dispose(), the caller can assume that the cache is still operable after this method returns.
Declaration
void Clear()
Get(FacetLabel)
Lookup a category in the cache, returning its ordinal, or a negative number if the category is not in the cache.
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(FacetLabel, int) never returned true) it means the category does not exist. Otherwise, the category might still exist, but just be missing from the cache.
Declaration
int Get(FacetLabel categoryPath)
Parameters
Type | Name | Description |
---|---|---|
FacetLabel | categoryPath |
Returns
Type | Description |
---|---|
int |
Put(FacetLabel, int)
Add a category to the cache, with the given ordinal as the value.
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.
Declaration
bool Put(FacetLabel categoryPath, int ordinal)
Parameters
Type | Name | Description |
---|---|---|
FacetLabel | categoryPath | |
int | ordinal |
Returns
Type | Description |
---|---|
bool |