Class LruTaxonomyWriterCache

    • Constructor Detail

      • LruTaxonomyWriterCache

        public LruTaxonomyWriterCache​(int cacheSize)
    • Method Detail

      • hasRoom

        public boolean hasRoom​(int n)
        Description copied from interface: TaxonomyWriterCache
        Sometimes the cache is either unlimited in size, or limited by a very big size, and in that case when we add a lot of categories it might make sense to pre-load the cache with all the existing categories. However, this pre-load does not make sense when the allowed cache size is small. The hasRoom() method allows to differentiate between these cases.

        After hasRoom(n) returned true, the following n put() should return false (meaning that the cache was not cleared).

        Specified by:
        hasRoom in interface TaxonomyWriterCache
      • close

        public void close()
        Description copied from interface: TaxonomyWriterCache
        Let go of whatever resources the cache is holding. After a close(), this object can no longer be used.
        Specified by:
        close in interface TaxonomyWriterCache
      • get

        public int get​(CategoryPath categoryPath)
        Description copied from interface: TaxonomyWriterCache
        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() never returned true) it means the category does not exist. Otherwise, the category might still exist, but just be missing from the cache.

        Specified by:
        get in interface TaxonomyWriterCache
      • put

        public boolean put​(CategoryPath categoryPath,
                           int ordinal)
        Description copied from interface: TaxonomyWriterCache
        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.

        Specified by:
        put in interface TaxonomyWriterCache