Class DefaultCache

java.lang.Object
org.casbin.jcasbin.persist.cache.DefaultCache
All Implemented Interfaces:
Cache

public class DefaultCache extends Object implements Cache
  • Field Details

  • Constructor Details

    • DefaultCache

      public DefaultCache()
  • Method Details

    • set

      public void set(String key, boolean value, Duration ttl)
      Set the cache value with an optional time-to-live (TTL).
      Parameters:
      key - The cache key to store the value.
      value - The boolean value to be stored in the cache.
      ttl - The time-to-live for the cache item; if null or negative, the item will not expire.
    • set

      public void set(String key, boolean value)
      Set the cache value without a TTL.
      Parameters:
      key - The cache key to store the value.
      value - The boolean value to be stored in the cache.
    • set

      public boolean set(String key, boolean value, Object... extra)
      Set puts key and value into cache. The first extra parameter should be a java.time.LocalDateTime object denoting the expected survival time. If survival time equals 0 or less, the key will always be valid.
      Specified by:
      set in interface Cache
      Parameters:
      key - the key to store
      value - the value to store
      extra - additional parameters (e.g., expiration time)
      Returns:
      true if successful, false otherwise
    • get

      public boolean get(String key)
      Get the value from the cache, handling expiration.
      Specified by:
      get in interface Cache
      Parameters:
      key - The cache key to retrieve the value.
      Returns:
      The value corresponding to the key.
      Throws:
      CasbinCacheException - If the key does not exist in the cache.
    • delete

      public void delete(String key) throws CasbinCacheException
      Delete the value from the cache.
      Specified by:
      delete in interface Cache
      Parameters:
      key - The cache key to delete the value.
      Throws:
      CasbinCacheException
    • clear

      public void clear()
      Clear the entire cache.
      Specified by:
      clear in interface Cache