Class PrefixMappedItemCache


  • public class PrefixMappedItemCache
    extends Object
    A semi-persistent storage for GoogleCloudStorageItemInfo that maintains indexes based on the item's bucket and object name. In addition to caching StorageResourceId to item mappings, it provides options for storing groups of items under similar bucket and object name prefixes.
    • Constructor Detail

      • PrefixMappedItemCache

        public PrefixMappedItemCache​(Duration maxEntryAge)
        Creates a new PrefixMappedItemCache.
        Parameters:
        maxEntryAge - time after which entries in cache expire.
    • Method Detail

      • getItem

        @Nullable
        public GoogleCloudStorageItemInfo getItem​(StorageResourceId id)
        Gets the cached item associated with the given resource id.
        Parameters:
        id - the resource id of the item to get.
        Returns:
        the cached item associated with the given resource id, null if the item isn't cached or it has expired in the cache.
      • putItem

        @Nullable
        public GoogleCloudStorageItemInfo putItem​(GoogleCloudStorageItemInfo item)
        Inserts an item into the cache. If an item with the same resource id is present, it is overwritten by the new item.
        Parameters:
        item - the item to insert. The item must have a valid resource id.
        Returns:
        the overwritten item, null if no item was overwritten.
      • removeItem

        @Nullable
        public GoogleCloudStorageItemInfo removeItem​(StorageResourceId id)
        Removes the item from the cache. If the item has expired, associated lists are invalidated.
        Parameters:
        id - the resource id of the item to remove.
        Returns:
        the removed item, null if no item was removed.
      • invalidateBucket

        public void invalidateBucket​(String bucket)
        Invalidates all cached items and lists associated with the given bucket.
        Parameters:
        bucket - the bucket to invalidate. This must not be null.
      • invalidateAll

        public void invalidateAll()
        Invalidates all entries in the cache.