Package org.casbin.jcasbin.persist.cache
Class DefaultCache
- java.lang.Object
-
- org.casbin.jcasbin.persist.cache.DefaultCache
-
-
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).
-
-
-
Field Detail
-
cache
private final java.util.Map<java.lang.String,CacheItem> cache
-
-
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.
-
get
public boolean get(java.lang.String key)
Get the value from the cache, handling expiration.- Specified by:
get
in interfaceCache
- 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(java.lang.String key) throws CasbinCacheException
Delete the value from the cache.- Specified by:
delete
in interfaceCache
- Parameters:
key
- The cache key to delete the value.- Throws:
CasbinCacheException
-
-