daviediao-code opened a new pull request, #1736:
URL: https://github.com/apache/casbin/pull/1736

   ## Problem
   
   When `CachedEnforcer` is used with a WatcherEx (e.g., Redis watcher for 
distributed cache invalidation), the `SetWatcher()` callback is never set. This 
means when another instance modifies the policy, the cache is never 
invalidated, and stale decisions are returned forever.
   
   ## Root Cause
   
   `Enforcer.SetWatcher()` (enforcer.go:249) explicitly skips setting a 
callback for WatcherEx implementations.
   
   ## Fix
   
   Override `SetWatcher()` in both `CachedEnforcer` and `SyncedCachedEnforcer` 
to set a callback even for WatcherEx. The callback calls `InvalidateCache()` + 
`LoadPolicy()`.
   
   ## Files Changed
   
   - `enforcer_cached.go`: SetWatcher override with WatcherEx-aware callback
   - `enforcer_cached_synced.go`: Same fix for SyncedCachedEnforcer
   - `enforcer_cached_watcher_test.go`: 5 new tests
   
   ## Tests
   
   All existing tests pass (18s). New tests cover WatcherEx callback, basic 
Watcher callback, direct InvalidateCache, and TTL behavior.
   
   **PR #1729**


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to