Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve removePolicy and removePolicies in CachedEnforcer #446

Merged
merged 4 commits into from
Dec 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/main/java/org/casbin/jcasbin/main/CachedEnforcer.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,10 @@ public void loadPolicy() {
* @param params The parameters of the policy to be removed.
* @return True if the policy was removed, false otherwise.
*/
@Override
public boolean removePolicy(String... params){
if (enableCache.get()) {
String key = getKey(params);
String key = getKey((Object[]) params);
if (key != null) {
cache.delete(key);
}
Expand All @@ -193,6 +194,23 @@ public boolean removePolicies(List<List<String>> rules) {
return super.removePolicies(rules);
}

/**
* Removes multiple policies from the enforcer.
*
* @param rules The list of policies to be removed.
* @return True if the policies were removed, false otherwise.
*/
@Override
public boolean removePolicies(String[][] rules) {
if (rules != null && enableCache.get()) {
for (String[] rule : rules) {
String key = getKey((Object[]) rule);
cache.delete(key);
}
}
return super.removePolicies(rules);
}

/**
* Retrieves a cached result based on the key.
*
Expand Down