Class DefaultCache

  • All Implemented Interfaces:
    Cache

    public class DefaultCache
    extends java.lang.Object
    implements Cache
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.String,​CacheItem> cache  
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultCache()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clear the entire cache.
      void delete​(java.lang.String key)
      Delete the value from the cache.
      boolean get​(java.lang.String key)
      Get the value from the cache, handling expiration.
      void set​(java.lang.String key, boolean value)
      Set the cache value without a TTL.
      boolean set​(java.lang.String key, boolean value, java.lang.Object... extra)
      Set puts key and value into cache.
      void set​(java.lang.String key, boolean value, java.time.Duration ttl)
      Set the cache value with an optional time-to-live (TTL).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • cache

        private final java.util.Map<java.lang.String,​CacheItem> cache
    • Constructor Detail

      • DefaultCache

        public DefaultCache()
    • Method Detail

      • set

        public void set​(java.lang.String key,
                        boolean value,
                        java.time.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​(java.lang.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​(java.lang.String key,
                           boolean value,
                           java.lang.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​(java.lang.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.
      • clear

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