Class SoftCache<K,​V>

    • Constructor Detail

      • SoftCache

        public SoftCache()
      • SoftCache

        public SoftCache​(int initialSize)
    • Method Detail

      • createCache

        protected Map<K,​SoftCache.CacheEntry<V>> createCache​(int initialSize)
        This method should be over-ridden by subclasses to change the underlying cache implementation and implement features like LRU caches...
      • containsKey

        public boolean containsKey​(K key)
      • containsValue

        public boolean containsValue​(V val)
      • put

        public V put​(K key,
                     V value)
        Adds an object to the cache.
      • putIfAbsent

        public V putIfAbsent​(K key,
                             V value)
        If the specified key is not already associated with a value, associate it with the given value. This is equivalent to
        Returns:
        The value that was in the cache, null if none was there before
      • putAll

        public void putAll​(Map<? extends K,​? extends V> map)
      • putAllIfAbsent

        public void putAllIfAbsent​(Map<? extends K,​? extends V> map)
      • putAllIfAbsent

        public void putAllIfAbsent​(Map<? extends K,​? extends V> map,
                                   long loadTimeInMillis)
      • get

        public V get​(K key)
        Gets an object from the cache.
      • remove

        public V remove​(K key)
        Removes an object from the cache.
      • keySet

        public Set<K> keySet()
      • removeMatchingKeys

        public Set<V> removeMatchingKeys​(com.google.common.base.Predicate<K> predicate)
      • cleanup

        public final void cleanup()
        Iterates through the cache and cleans up any cache references that have been collected by the garbage collector.
      • filter

        public Collection<V> filter​(Collection<K> request)
        This convenience method filters a request by removing all items in the request which are in the cache and returning the corresponding values.

        Synchronization note: this method is not synchronized on the cache. Thus, if replacements are performed during a canonicalization, it is undefined which object is returned. Similarly, this function is not synchronized on the request collection, so if synchronization is required, it must be performed externally.

        Parameters:
        request - The list of items to be fetched from the backing store. This collection must be modifiable.
      • canonicalize

        public void canonicalize​(Map<K,​V> returnVal)
        This convenience method takes a map of items returned from the backing store and replaces references loaded from the backing store with items in the cache.

        A call to canonicalize will typically be followed by a putAll on the returnVal, so that future requests to the cache will return the new items loaded.

        Synchronization note: this method is not synchronized on the cache. Thus, if replacements are performed during a canonicalization, it is undefined which object is returned. Similarly, this function is not synchronized on the returnVal map, so if synchronization is required, it must be performed externally.

        Parameters:
        returnVal - The map of items to be canonicalized. This map must be modifiable.