Class KMemoryDataCache

java.lang.Object
com.kheops.util.KAbstractDataCache
com.kheops.util.KMemoryDataCache
All Implemented Interfaces:
KSchedulerClient

public class KMemoryDataCache extends KAbstractDataCache implements KSchedulerClient
A class used to store and retrieve data stored on memory.
  • Constructor Details

    • KMemoryDataCache

      public KMemoryDataCache(long maximumSize)
      Constructs a KMemoryDataCache with the specified maximum size
      Parameters:
      maximumSize - the maximum size of memory data cache allowed
  • Method Details

    • store

      public void store(String key, byte[] data)
      Specified by:
      store in class KAbstractDataCache
    • store

      public void store(String key, byte[] data, long timeTolive)
      Stores the specified data in memory cache using the specified key. The specified time to live (in ms) is the data expiration time. After this time is expired, the data will be removed from the cache. If timeToLive is CacheConstants.CACHE_TIMEOUT_NEVER_EXPIRE, expiration will be disabled for this data (it will stay in cache until explicitly removed using the remove(String key) method.
      Parameters:
      key - the key of the KMemoryDataCache where to store the data
      data - the data to be stored
      timeTolive - amount of time before the data expires
    • retrieve

      public byte[] retrieve(String key)
      Retrieves the data previously stored using the specified key. If the data does not exist, no exception is thrown but the method returns null.
      Parameters:
      key - unique identifier used to search for the corresponding data
      Returns:
      data the data retrieved from memory
      this method keeps the count of sucessfull and unsecessfull data retrieval
    • contains

      public boolean contains(String key)
      Checks if the table contains the data with the specified keys
      Parameters:
      key - the corresponding key
      Returns:
      the boolean value of the result
    • getCurrentSize

      public long getCurrentSize()
      Gets the memory cache current size
      Overrides:
      getCurrentSize in class KAbstractDataCache
      Returns:
      the current cache size
    • getMaximumSize

      public long getMaximumSize()
      Gets the memory cache maximum allowed size
      Overrides:
      getMaximumSize in class KAbstractDataCache
      Returns:
      the maximum cache size
    • remove

      public void remove(String key)
      Removes the memory cache with the specified key
      Parameters:
      key - the key of the data to be removed
    • schCallback

      public void schCallback(int jobId)
      This method is called by the KScheduler to remove the expired data
      Specified by:
      schCallback in interface KSchedulerClient
      Parameters:
      jobId - the corresponding job Id
    • removeAll

      public void removeAll()
      Specified by:
      removeAll in class KAbstractDataCache
    • removeMatching

      public void removeMatching(String partialKey)
      Specified by:
      removeMatching in class KAbstractDataCache
    • export

      public void export(KAbstractDataCache cache) throws IOException
      Specified by:
      export in class KAbstractDataCache
      Throws:
      IOException
    • getCount

      public long getCount()
      Specified by:
      getCount in class KAbstractDataCache
    • getCount

      public long getCount(String partialKey)
      Specified by:
      getCount in class KAbstractDataCache
    • getCurrentSize

      public long getCurrentSize(String partialKey)
      Specified by:
      getCurrentSize in class KAbstractDataCache