Class CachedEnforcer
java.lang.Object
org.casbin.jcasbin.main.CoreEnforcer
org.casbin.jcasbin.main.InternalEnforcer
org.casbin.jcasbin.main.ManagementEnforcer
org.casbin.jcasbin.main.Enforcer
org.casbin.jcasbin.main.CachedEnforcer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Cacheprivate final AtomicBooleanprivate Durationprivate static final ReadWriteLockFields inherited from class CoreEnforcer
acceptJsonRequest, adapter, autoBuildRoleLinks, autoNotifyDispatcher, autoNotifyWatcher, autoSave, condRmMap, dispatcher, fm, model, modelPath, rmMap, watcher -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor for CachedEnforcer.CachedEnforcer(String modelPath) Initializes an enforcer with a model file.CachedEnforcer(String modelPath, String policyFile) Initializes an enforcer with a model file and a policy file.CachedEnforcer(String modelPath, String policyFile, boolean enableLog) Initializes an enforcer with a model file, a policy file, and a logging flag.CachedEnforcer(String modelPath, Adapter adapter) Initializes an enforcer with a model file and a database adapter.Initializes an enforcer with a model.CachedEnforcer(Model m, Adapter adapter) Initializes an enforcer with a model and a database adapter. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears all policies from the enforcer.booleanEnforces a policy based on the given request values.getCache()Retrieves the current cache used by this CachedEnforcer.private booleangetCachedResult(String key) Retrieves a cached result based on the key.getCacheKey(Object... params) Retrieves a cache key from the given parameters.private StringGenerates a cache key from the given parameters.voidInvalidates all cached decisions.voidLoads policies into the enforcer.booleanremovePolicies(String[][] rules) Removes multiple policies from the enforcer.booleanremovePolicies(List<List<String>> rules) Removes multiple policies from the enforcer.booleanremovePolicy(String... params) Removes a policy from the enforcer.voidSets a custom cache implementation.private voidsetCachedResult(String key, boolean result, Duration expireTime) Stores a result in the cache with an expiration time.voidsetExpireTime(Duration expireTime) Sets the expiration time for cached items.Methods inherited from class Enforcer
addPermissionForUser, addPermissionForUser, addRoleForUser, addRoleForUserInDomain, batchEnforce, batchEnforceWithMatcher, deletePermission, deletePermission, deletePermissionForUser, deletePermissionForUser, deletePermissionsForUser, deleteRole, deleteRoleForUser, deleteRoleForUserInDomain, deleteRolesForUser, deleteUser, getImplicitPermissionsForUser, getImplicitPermissionsForUserInDomain, getImplicitRolesForUser, getImplicitUsersForRole, getNamedImplicitPermissionsForUser, getNamedPermissionsForUser, getPermissionsForUser, getPermissionsForUserInDomain, getRolesForUser, getRolesForUserInDomain, getUsersForRole, getUsersForRoleInDomain, hasPermissionForUser, hasPermissionForUser, hasRoleForUser, updatePermissionForUserMethods inherited from class ManagementEnforcer
addFunction, addGroupingPolicies, addGroupingPolicies, addGroupingPolicy, addGroupingPolicy, addNamedGroupingPolicies, addNamedGroupingPolicies, addNamedGroupingPolicy, addNamedGroupingPolicy, addNamedPolicies, addNamedPoliciesEx, addNamedPolicy, addNamedPolicy, addPolicies, addPolicies, addPolicy, addPolicy, getAllActions, getAllNamedActions, getAllNamedObjects, getAllNamedRoles, getAllNamedSubjects, getAllObjects, getAllRoles, getAllSubjects, getFilteredGroupingPolicy, getFilteredNamedGroupingPolicy, getFilteredNamedPolicy, getFilteredPolicy, getGroupingPolicy, getNamedGroupingPolicy, getNamedPolicy, getPermittedActions, getPolicy, hasGroupingPolicy, hasGroupingPolicy, hasNamedGroupingPolicy, hasNamedGroupingPolicy, hasNamedPolicy, hasNamedPolicy, hasPolicy, hasPolicy, removeFilteredGroupingPolicy, removeFilteredNamedGroupingPolicy, removeFilteredNamedPolicy, removeFilteredPolicy, removeGroupingPolicies, removeGroupingPolicies, removeGroupingPolicy, removeGroupingPolicy, removeNamedGroupingPolicies, removeNamedGroupingPolicies, removeNamedGroupingPolicy, removeNamedGroupingPolicy, removeNamedPolicies, removeNamedPolicy, removeNamedPolicy, removePolicy, updateGroupingPolicy, updateNamedGroupingPolicy, updateNamedPolicy, updatePolicyMethods inherited from class InternalEnforcer
addPolicies, addPolicy, buildIncrementalRoleLinks, getDomainIndex, removeFilteredPolicy, removePolicies, removePolicy, updatePolicyMethods inherited from class CoreEnforcer
addNamedDomainLinkConditionFunc, addNamedDomainMatchingFunc, addNamedLinkConditionFunc, addNamedMatchingFunc, buildConditionalRoleLinks, buildRoleLinks, enableAcceptJsonRequest, enableAutoBuildRoleLinks, enableAutoSave, enableEnforce, enableLog, enforceEx, enforceExWithMatcher, enforceWithMatcher, getAdapter, getAviatorEval, getModel, getNamedRoleManager, getRmMap, getRoleManager, initialize, isAutoNotifyDispatcher, isAutoNotifyWatcher, isFiltered, loadFilteredPolicy, loadModel, mustUseDispatcher, newModel, newModel, newModel, resetExpressionEvaluator, savePolicy, setAdapter, setAutoNotifyDispatcher, setAutoNotifyWatcher, setAviatorEvaluator, setDispatcher, setEffector, setModel, setNamedDomainLinkConditionFuncParams, setNamedLinkConditionFuncParams, setNamedRoleManager, setRoleManager, setRoleManager, setWatcher, validateEnforce
-
Field Details
-
expireTime
-
cache
-
enableCache
-
READ_WRITE_LOCK
-
-
Constructor Details
-
CachedEnforcer
public CachedEnforcer()Default constructor for CachedEnforcer. Initializes a new CachedEnforcer with a default cache. -
CachedEnforcer
-
CachedEnforcer
-
CachedEnforcer
-
CachedEnforcer
-
CachedEnforcer
Initializes an enforcer with a model file.- Parameters:
modelPath- The path of the model file.
-
CachedEnforcer
-
-
Method Details
-
getCache
Retrieves the current cache used by this CachedEnforcer.- Returns:
- The cache instance.
-
enforce
Enforces a policy based on the given request values.- Overrides:
enforcein classCoreEnforcer- Parameters:
rvals- The request values, usually in the format of (sub, obj, act).- Returns:
- The result of the enforcement (true or false).
-
loadPolicy
public void loadPolicy()Loads policies into the enforcer. If caching is enabled, clears the cache before loading policies.- Overrides:
loadPolicyin classCoreEnforcer
-
removePolicy
Removes a policy from the enforcer.- Overrides:
removePolicyin classManagementEnforcer- Parameters:
params- The parameters of the policy to be removed.- Returns:
- True if the policy was removed, false otherwise.
-
removePolicies
Removes multiple policies from the enforcer.- Overrides:
removePoliciesin classManagementEnforcer- Parameters:
rules- The list of policies to be removed.- Returns:
- True if the policies were removed, false otherwise.
-
removePolicies
Removes multiple policies from the enforcer.- Overrides:
removePoliciesin classManagementEnforcer- Parameters:
rules- The list of policies to be removed.- Returns:
- True if the policies were removed, false otherwise.
-
getCachedResult
Retrieves a cached result based on the key.- Parameters:
key- The cache key.- Returns:
- The cached result, or null if not found.
-
setExpireTime
Sets the expiration time for cached items.- Parameters:
expireTime- The duration after which cached items will expire.
-
setCache
Sets a custom cache implementation.- Parameters:
cache- The cache instance to use.
-
setCachedResult
-
getKey
-
getCacheKey
-
invalidateCache
public void invalidateCache()Invalidates all cached decisions. -
clearPolicy
public void clearPolicy()Clears all policies from the enforcer. If caching is enabled, clears the cache before clearing policies.- Overrides:
clearPolicyin classCoreEnforcer
-