Class ContextHolderCache


  • @Singleton
    public class ContextHolderCache
    extends Object
    A thread safe cache for ContextHolder objects.
    • Constructor Detail

      • ContextHolderCache

        @Inject
        public ContextHolderCache​(ContextCacheSize contextCacheSize)
        Constructs a thread safe ContextHolderCache.
        Parameters:
        contextCacheSize - - provides the ContextHolderCache with it's desired max size.
    • Method Detail

      • get

        public ContextHolder get​(String key)
        Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
        Parameters:
        key - - the key whose associated value is to be returned.
        Returns:
        the cached value associated with the specified key, or null if no cache entry is held with the key.
      • remove

        public ContextHolder remove​(String key)
        Remove an entry from the cache.
        Parameters:
        key - - the key whose mapping is to be removed from the cache.
        Returns:
        The item removed from the cache, or null if there was no mapping for the key.
      • createCachedContextHolder

        public ContextHolder createCachedContextHolder()
        Creates a new cache key, creates and caches a new ContextHolder using the key and returns the newly cached object.
        Returns:
        the newly cached ContextHolder object.
      • put

        public ContextHolder put​(String key,
                                 ContextHolder contextHolder)
        Associates the specified value with the specified key in this cache. If the cache previously contained a mapping for the key, the old value is replaced.
        Parameters:
        key - - key with which the specified value is to be associated
        contextHolder - - the ContextHolder associated with the specified key
        Returns:
        the previous value associated with key, or null if there was no entry for key. (A null return can also indicate that the cache previously associated null with key.)
      • size

        public int size()
        Returns the number of key-ContextHolder entries in the cache.
        Returns:
        the number of key-ContextHolder entries in the cache.
      • getMaxSize

        public int getMaxSize()
        Get the bounded size of the cache. This is the maximum number of entries that may be held. When the number of entries in the cache equals this max size, then adding more entries will result in the least recently used number of entries being removed to make space for the newly added entries.
        Returns:
        the bounded size of the cache.