Class DefaultCache

  • All Implemented Interfaces:
    Cache

    public class DefaultCache
    extends Object
    implements Cache
    • Constructor Detail

      • DefaultCache

        public DefaultCache()
      • DefaultCache

        public DefaultCache​(int maxSize)
    • Method Detail

      • put

        public void put​(String id,
                        Object value)
        Description copied from interface: Cache
        Adds or replaces a value in the cache.
        Specified by:
        put in interface Cache
        Parameters:
        id - The object id
        value - The value to cache
      • get

        public <T> T get​(String id,
                         Function<? super String,​T> mappingFunction)
        Description copied from interface: Cache
        Returns the value associated with the given id. If there is no association, the mapping function is used to calculate a value. This value will be stored in the cache.
        Specified by:
        get in interface Cache
        Type Parameters:
        T - the type of object to return from the cache
        Parameters:
        id - The object id
        mappingFunction - The function to compute a value if the cache is not in the cache
        Returns:
        The value associated with given id
      • getIfPresent

        public <T> T getIfPresent​(String id)
        Description copied from interface: Cache
        Returns the value associated with the given id if it exists in the cache. If there is no association, null is returned.
        Specified by:
        getIfPresent in interface Cache
        Type Parameters:
        T - the type of object to return from the cache
        Parameters:
        id - The object id
        Returns:
        The value associated with given id
      • invalidate

        public void invalidate​(String id)
        Description copied from interface: Cache
        Invalidates the cache entry mapped to given id.
        Specified by:
        invalidate in interface Cache
      • invalidateAll

        public void invalidateAll()
        Description copied from interface: Cache
        Invalidates all cache entries.
        Specified by:
        invalidateAll in interface Cache