Interface MemoryCache

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static interface  MemoryCache.CacheListener
      Provides the interface for cache clients to be notified of key events.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      boolean add​(java.lang.Object key, Cacheable clientObject)
      Attempts to add the Cacheable object referenced by the key.
      boolean add​(java.lang.Object key, java.lang.Object clientObject, long objectSize)
      Attempts to add the object clientObject, with size objectSize and referred to by key to the cache.
      void addCacheListener​(MemoryCache.CacheListener listener)
      Adds a new cacheListener, which will be sent notification whenever an entry is removed from the cache.
      void clear()
      Empties the cache.
      boolean contains​(java.lang.Object key)
      Discovers whether or not this cache contains the object referenced by key .
      long getCapacity()
      Retrieves the maximum size of the cache.
      long getFreeCapacity()
      Retrieves the available space for storing new items.
      long getLowWater()
      Retrieves the low water value of the MemoryCache.
      java.lang.String getName()  
      int getNumObjects()
      Retrieve the number of items stored in the MemoryCache.
      java.lang.Object getObject​(java.lang.Object key)
      Retrieves the requested item from the cache.
      long getUsedCapacity()
      Retrieves the amount of used MemoryCache space.
      void remove​(java.lang.Object key)
      Remove an object from the MemoryCache referenced by key.
      void removeCacheListener​(MemoryCache.CacheListener listener)
      Removes a CacheListener, notifications of events will no longer be sent to this listener.
      void setCapacity​(long capacity)
      Sets the maximum capacity for this cache.
      void setLowWater​(long loWater)
      Sets the new low water capacity value for this MemoryCache.
      void setName​(java.lang.String name)  
    • Method Detail

      • setName

        void setName​(java.lang.String name)
      • getName

        java.lang.String getName()
      • addCacheListener

        void addCacheListener​(MemoryCache.CacheListener listener)
        Adds a new cacheListener, which will be sent notification whenever an entry is removed from the cache.
        Parameters:
        listener - the new MemoryCache.CacheListener
      • removeCacheListener

        void removeCacheListener​(MemoryCache.CacheListener listener)
        Removes a CacheListener, notifications of events will no longer be sent to this listener.
        Parameters:
        listener - the cache listener to remove.
      • contains

        boolean contains​(java.lang.Object key)
        Discovers whether or not this cache contains the object referenced by key . Currently no interface exists to discover if an object resides in the cache by referencing itself.
        Parameters:
        key - the key which the object is referenced by.
        Returns:
        true if the key is found in the cache, false otherwise.
      • add

        boolean add​(java.lang.Object key,
                    java.lang.Object clientObject,
                    long objectSize)
        Attempts to add the object clientObject, with size objectSize and referred to by key to the cache. objectSize is the size in cache units, but is not checked for accuracy. Returns whether or not the add was successful.

        Note that the size passed in may be used, rather than the real size of the object. In some implementations, the accuracy of the space used calls will depend on the collection of these sizes, rather than actual size.

        This method should be declared synchronized when it is implemented.

        Parameters:
        key - an object used to reference the cached item.
        clientObject - the item to be cached.
        objectSize - the size of the item in cache units.
        Returns:
        true if object was added, false otherwise.
      • add

        boolean add​(java.lang.Object key,
                    Cacheable clientObject)
        Attempts to add the Cacheable object referenced by the key. No explicit size value is required as this method queries the Cacheable to discover the size.

        This method should be declared synchronized when it is implemented.

        Parameters:
        key - an object used to reference the cached item.
        clientObject - the item to be cached.
        Returns:
        true if object was added, false otherwise.
        See Also:
        Cacheable
      • remove

        void remove​(java.lang.Object key)
        Remove an object from the MemoryCache referenced by key. If the object is already absent, this method simply returns without indicating the absence.
        Parameters:
        key - an Object used to represent the item to remove.
      • getObject

        java.lang.Object getObject​(java.lang.Object key)
        Retrieves the requested item from the cache. If key is null or the item is not found, this method returns null.
        Parameters:
        key - an Object used to represent the item to retrieve.
        Returns:
        the requested Object if found, null otherwise.
      • clear

        void clear()
        Empties the cache. After calling clear() on a MemoryCache, calls relating to used capacity and number of items should return zero and the free capacity should be the maximum capacity.

        This method should be declared synchronized when it is implemented and should notify all CacheListeners of entries removed.

      • getNumObjects

        int getNumObjects()
        Retrieve the number of items stored in the MemoryCache.
        Returns:
        the number of items in the cache.
      • getCapacity

        long getCapacity()
        Retrieves the maximum size of the cache.
        Returns:
        the maximum size of the MemoryCache.
      • getUsedCapacity

        long getUsedCapacity()
        Retrieves the amount of used MemoryCache space. The value returned is in cache units.
        Returns:
        the long value of the number of cache units used by cached items.
      • getFreeCapacity

        long getFreeCapacity()
        Retrieves the available space for storing new items.
        Returns:
        the long value of the remaining space for storing cached items.
      • getLowWater

        long getLowWater()
        Retrieves the low water value of the MemoryCache. When a MemoryCache runs out of free space, it must remove some items if it wishes to add any more. It continues removing items until the low water level is reached. Not every MemoryCache necessarily uses the low water system, so this may not return a useful value.
        Returns:
        the low water value of the MemoryCache.
      • setLowWater

        void setLowWater​(long loWater)
        Sets the new low water capacity value for this MemoryCache. When a MemoryCache runs out of free space, it must remove some items if it wishes to add any more. It continues removing items until the low water level is reached. Not every MemoryCache necessarily uses the low water system, so this method may not have any actual effect in some implementations.
        Parameters:
        loWater - the new low water value.
      • setCapacity

        void setCapacity​(long capacity)
        Sets the maximum capacity for this cache. This capacity has no impact on the number of items stored in the MemoryCache, except that every item must have a positive size. Generally the used capacity is the total of the sizes of all stored items.
        Parameters:
        capacity - the new capacity.