Class MemCache

java.lang.Object
com.avoka.tm.util.MemCache

public class MemCache extends Object

Provides an in memory cache for high frequency read only access values. Cached values are keyed on the specified cache key and the executing service's Organization security context.

When using the memory cache ensure you do not put excessively large values in the cache which would impact the application servers memory usage.

Examples

Put Value in Cache

This examples puts a value in the cache with a 12 hour timeout (720 mins) with AFTER_WRITE.

 import com.avoka.tm.util.*

 String value = "some big and expensive data..."

 new MemCache(MemCache.MemCacheExpiryPolicy.AFTER_WRITE)
     .setKey("Ref Data")
     .setTimeout(720)
     .setValue(value)

 

This example puts a value in the cache with a 12 hour timeout (720 mins) defaulting to AFTER_ACCESS.

new MemCache() .setKey("Ref Data") .setTimeout(720) .setValue(value)

Clear a cache entry using the key

This example clears the cache entry associated with the specific key.

 import com.avoka.tm.util.*

 boolean cleared = new MemCache()
     .setKey("Ref Data")
     .clear() 

Get Value from Cache

This examples gets a value from the cache with a 12 hour cache timeout (720 mins).

 import com.avoka.tm.util.*

 String value = new MemCache()
     .setKey("Ref Data")
     .setTimeout(720)
     .getValue() 
Since:
5.0.0
See Also:
  • Constructor Details

  • Method Details

    • setKey

      public MemCache setKey(String key)
      Set the mem cache key parameter.
      Parameters:
      key - the cache key
      Returns:
      the mem cache
    • setTimeout

      public MemCache setTimeout(int timeoutMins)
      Set the mem cache timeout in minutes.
      Parameters:
      timeoutMins - the mem cache timeout in minutes, must be a positive value.
      Returns:
      the mem cache
    • getValue

      public Object getValue()
      Return the memory cached object, or null if not found or has expired.
      Returns:
      the memory cached object, or null if not found or has expired.
    • setValue

      public void setValue(Object value)
      Set the value to cache in memory with the specified key and cacheTimeout properties.
      Parameters:
      value - the value to set in the cache for the specified key and cacheTimeout property
    • clear

      public boolean clear()
      clear the mem cache as a whole or at least by specific key. .
      Returns:
      boolean true if the cache is cleared successfully
      Since:
      21.11