This is an automated email from the ASF dual-hosted git repository.
hsluoyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/casbin.git
The following commit(s) were added to refs/heads/master by this push:
new c519ae0 fix: keep decision cache consistent with EnableEnforce
c519ae0 is described below
commit c519ae05c5a530e6df9ea87f72a8e076d493db51
Author: Yang Luo <[email protected]>
AuthorDate: Tue Oct 20 22:05:10 2026 +0800
fix: keep decision cache consistent with EnableEnforce
---
enforcer.go | 1 +
enforcer_cached.go | 2 +-
enforcer_cached_synced.go | 2 +-
3 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/enforcer.go b/enforcer.go
index f2752e9..b78b920 100644
--- a/enforcer.go
+++ b/enforcer.go
@@ -637,6 +637,7 @@ func (e *Enforcer) initRmMap() {
// EnableEnforce changes the enforcing state of Casbin, when Casbin is
disabled, all access will be allowed by the Enforce() function.
func (e *Enforcer) EnableEnforce(enable bool) {
e.enabled = enable
+ e.bumpPolicyVersion()
}
// EnableAutoNotifyWatcher controls whether to save a policy rule
automatically notify the Watcher when it is added or removed.
diff --git a/enforcer_cached.go b/enforcer_cached.go
index 0fc930f..10f9e45 100644
--- a/enforcer_cached.go
+++ b/enforcer_cached.go
@@ -69,7 +69,7 @@ func (e *CachedEnforcer) EnableCache(enableCache bool) {
// Enforce decides whether a "subject" can access a "object" with the
operation "action", input parameters are usually: (sub, obj, act).
// if rvals is not string , ignore the cache.
func (e *CachedEnforcer) Enforce(rvals ...interface{}) (bool, error) {
- if atomic.LoadInt32(&e.enableCache) == 0 {
+ if atomic.LoadInt32(&e.enableCache) == 0 || !e.enabled {
return e.Enforcer.Enforce(rvals...)
}
diff --git a/enforcer_cached_synced.go b/enforcer_cached_synced.go
index 9301c95..43f51ad 100644
--- a/enforcer_cached_synced.go
+++ b/enforcer_cached_synced.go
@@ -64,7 +64,7 @@ func (e *SyncedCachedEnforcer) EnableCache(enableCache bool) {
// Enforce decides whether a "subject" can access a "object" with the
operation "action", input parameters are usually: (sub, obj, act).
// if rvals is not string , ignore the cache.
func (e *SyncedCachedEnforcer) Enforce(rvals ...interface{}) (bool, error) {
- if atomic.LoadInt32(&e.enableCache) == 0 {
+ if atomic.LoadInt32(&e.enableCache) == 0 || !e.enabled {
return e.SyncedEnforcer.Enforce(rvals...)
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]