Package play.cache

Class Cache

java.lang.Object
play.cache.Cache

@NullMarked @CheckReturnValue public abstract class Cache extends Object
The Cache. Mainly an interface to Memcached or EhCache. Choose cache implementation by having your project depend on either one of these RePlay packages: `memcached` or `ehcache`. Without one of these packages the fall-back "dummy" cache is used, which does not do any caching.

Note: When specifying expiration == "0s" (zero seconds) the actual expiration-time may vary between different cache implementations

  • Constructor Details

    • Cache

      public Cache()
  • Method Details

    • set

      public static void set(String key, @Nullable Object value, String expiration)
      Set an element.
      Parameters:
      key - Element key
      value - Element value
      expiration - Ex: 10s, 3mn, 8h
    • get

      public static <T> @Nullable T get(String key)
      Retrieve an object.
      Parameters:
      key - The element key
      Returns:
      The element value or null
    • delete

      public static void delete(String key)
      Delete an element from the cache.
      Parameters:
      key - The element key
    • clear

      public static void clear()
      Clear all data from cache.
    • init

      public static void init()
      Initialize the cache system.
    • stop

      public static void stop()
      Stop the cache system.