Class SyncedCachedEnforcer
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.SyncedEnforcer
org.casbin.jcasbin.main.SyncedCachedEnforcer
-
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.SyncedCachedEnforcer(String modelPath) Initializes an enforcer with a model file.SyncedCachedEnforcer(String modelPath, String policyFile) Initializes an enforcer with a model file and a policy file.SyncedCachedEnforcer(String modelPath, String policyFile, boolean enableLog) Initializes an enforcer with a model file, a policy file, and a logging flag.SyncedCachedEnforcer(String modelPath, Adapter adapter) Initializes an enforcer with a model file and a database adapter.Initializes an enforcer with a model.SyncedCachedEnforcer(Model m, Adapter adapter) Initializes an enforcer with a model and a database adapter. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddPolicies(String[][] rules) Adds multiple policies while checking and removing the cache.booleanaddPolicies(List<List<String>> rules) Adds multiple policies while checking and removing the cache.booleanAdds a single policy while checking and removing the cache.private booleancheckManyAndRemoveCache(String[][] rules) Checks and removes cache for multiple policies.private booleancheckManyAndRemoveCache(List<List<String>> rules) Checks and removes cache for multiple policies.private booleancheckOneAndRemoveCache(String... params) Checks and removes cache for a single policy.voidenableCache(boolean enable) Enables or disables caching.booleanPerforms an enforcement check based on given parameters, using the cache.private BooleangetCachedResult(String key) Retrieves a cached result based on the given key.getCacheKey(Object... params) Retrieves a cache key from the given parameters.private StringGenerates a key based on the given parameters.voidInvalidates the cache by clearing it.voidLoads the policy, clearing the cache if enabled.booleanremovePolicies(String[][] rules) Removes multiple policies while checking and removing the cache.booleanremovePolicies(List<List<String>> rules) Removes multiple policies while checking and removing the cache.booleanremovePolicy(String... params) Removes a single policy while checking and removing the cache.voidSets a custom cache.private voidsetCachedResult(String key, boolean result, Object... extra) Sets the cached result.voidsetExpireTime(Duration expireTime) Sets the cache expiration time.Methods inherited from class SyncedEnforcer
addGroupingPolicies, addGroupingPolicies, addGroupingPolicy, addGroupingPolicy, addNamedGroupingPolicies, addNamedGroupingPolicies, addNamedGroupingPolicy, addNamedGroupingPolicy, addNamedPolicies, addNamedPoliciesEx, addNamedPolicy, addNamedPolicy, addPermissionForUser, addPermissionForUser, addPolicy, addRoleForUser, addRoleForUserInDomain, batchEnforce, batchEnforceWithMatcher, buildRoleLinks, clearPolicy, deletePermission, deletePermission, deletePermissionForUser, deletePermissionForUser, deletePermissionsForUser, deleteRole, deleteRoleForUser, deleteRoleForUserInDomain, deleteRolesForUser, deleteUser, enforceEx, enforceExWithMatcher, enforceWithMatcher, getAllActions, getAllNamedActions, getAllNamedObjects, getAllNamedRoles, getAllObjects, getAllRoles, getAllSubjects, getFilteredGroupingPolicy, getFilteredNamedGroupingPolicy, getFilteredNamedPolicy, getFilteredPolicy, getGroupingPolicy, getImplicitPermissionsForUser, getImplicitRolesForUser, getNamedGroupingPolicy, getNamedImplicitPermissionsForUser, getNamedPermissionsForUser, getNamedPolicy, getPermissionsForUser, getPermissionsForUserInDomain, getPolicy, getRolesForUser, getRolesForUserInDomain, getUsersForRole, getUsersForRoleInDomain, hasGroupingPolicy, hasGroupingPolicy, hasNamedGroupingPolicy, hasNamedGroupingPolicy, hasNamedPolicy, hasNamedPolicy, hasPermissionForUser, hasPermissionForUser, hasPolicy, hasPolicy, hasRoleForUser, isAutoLoadingRunning, loadFilteredPolicy, removeFilteredGroupingPolicy, removeFilteredNamedGroupingPolicy, removeFilteredNamedPolicy, removeFilteredPolicy, removeGroupingPolicies, removeGroupingPolicies, removeGroupingPolicy, removeGroupingPolicy, removeNamedGroupingPolicies, removeNamedGroupingPolicies, removeNamedGroupingPolicy, removeNamedGroupingPolicy, removeNamedPolicies, removeNamedPolicy, removeNamedPolicy, removePolicy, savePolicy, setWatcher, startAutoLoadPolicy, stopAutoLoadPolicy, updateGroupingPolicy, updateNamedGroupingPolicy, updateNamedPolicy, updatePolicyMethods inherited from class Enforcer
getImplicitPermissionsForUserInDomain, getImplicitUsersForRole, updatePermissionForUserMethods inherited from class ManagementEnforcer
addFunction, getAllNamedSubjects, getPermittedActionsMethods inherited from class InternalEnforcer
addPolicies, addPolicy, buildIncrementalRoleLinks, getDomainIndex, removeFilteredPolicy, removePolicies, removePolicy, updatePolicyMethods inherited from class CoreEnforcer
addNamedDomainLinkConditionFunc, addNamedDomainMatchingFunc, addNamedLinkConditionFunc, addNamedMatchingFunc, buildConditionalRoleLinks, enableAcceptJsonRequest, enableAutoBuildRoleLinks, enableAutoSave, enableEnforce, enableLog, getAdapter, getAviatorEval, getModel, getNamedRoleManager, getRmMap, getRoleManager, initialize, isAutoNotifyDispatcher, isAutoNotifyWatcher, isFiltered, loadModel, mustUseDispatcher, newModel, newModel, newModel, resetExpressionEvaluator, setAdapter, setAutoNotifyDispatcher, setAutoNotifyWatcher, setAviatorEvaluator, setDispatcher, setEffector, setModel, setNamedDomainLinkConditionFuncParams, setNamedLinkConditionFuncParams, setNamedRoleManager, setRoleManager, setRoleManager, validateEnforce
-
Field Details
-
expireTime
-
cache
-
enableCache
-
READ_WRITE_LOCK
-
-
Constructor Details
-
SyncedCachedEnforcer
public SyncedCachedEnforcer()Default constructor. Initializes a new SyncedCachedEnforcer with a default cache. -
SyncedCachedEnforcer
-
SyncedCachedEnforcer
-
SyncedCachedEnforcer
-
SyncedCachedEnforcer
Initializes an enforcer with a model.- Parameters:
m- The model.
-
SyncedCachedEnforcer
Initializes an enforcer with a model file.- Parameters:
modelPath- The path of the model file.
-
SyncedCachedEnforcer
Initializes an enforcer with a model file, a policy file, and a logging flag.- Parameters:
modelPath- The path of the model file.policyFile- The path of the policy file.enableLog- Whether to enable logging for Casbin.
-
-
Method Details
-
enableCache
public void enableCache(boolean enable) Enables or disables caching.- Parameters:
enable- Whether to enable caching.
-
enforce
Performs an enforcement check based on given parameters, using the cache.- Overrides:
enforcein classSyncedEnforcer- Parameters:
rvals- Parameters for the enforcement check.- Returns:
- The result of the enforcement check.
-
loadPolicy
public void loadPolicy()Loads the policy, clearing the cache if enabled.- Overrides:
loadPolicyin classSyncedEnforcer
-
addPolicy
Adds a single policy while checking and removing the cache.- Overrides:
addPolicyin classSyncedEnforcer- Parameters:
params- Policy parameters.- Returns:
- Whether the addition was successful.
-
addPolicies
Adds multiple policies while checking and removing the cache.- Overrides:
addPoliciesin classSyncedEnforcer- Parameters:
rules- Policy rules.- Returns:
- Whether the addition was successful.
-
addPolicies
Adds multiple policies while checking and removing the cache.- Overrides:
addPoliciesin classSyncedEnforcer- Parameters:
rules- Policy rules.- Returns:
- Whether the addition was successful.
-
removePolicy
Removes a single policy while checking and removing the cache.- Overrides:
removePolicyin classSyncedEnforcer- Parameters:
params- Policy parameters.- Returns:
- Whether the removal was successful.
-
removePolicies
Removes multiple policies while checking and removing the cache.- Overrides:
removePoliciesin classSyncedEnforcer- Parameters:
rules- Policy rules.- Returns:
- Whether the removal was successful.
-
removePolicies
Removes multiple policies while checking and removing the cache.- Overrides:
removePoliciesin classSyncedEnforcer- Parameters:
rules- Policy rules.- Returns:
- Whether the removal was successful.
-
getCachedResult
-
setExpireTime
Sets the cache expiration time.- Parameters:
expireTime- The expiration time.
-
setCache
-
setCachedResult
-
getCacheKey
-
getKey
-
invalidateCache
public void invalidateCache()Invalidates the cache by clearing it. -
checkOneAndRemoveCache
Checks and removes cache for a single policy.- Parameters:
params- Policy parameters.- Returns:
- Whether the check was successful.
-
checkManyAndRemoveCache
-
checkManyAndRemoveCache
Checks and removes cache for multiple policies.- Parameters:
rules- Policy rules.- Returns:
- Whether the check was successful.
-