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-website.git
The following commit(s) were added to refs/heads/master by this push:
new da0899adf docs: add SyncedContextEnforcer and watcher notification on
commit
da0899adf is described below
commit da0899adfae38f5b04582525c0acb7168f0e748f
Author: Yang Luo <[email protected]>
AuthorDate: Wed Oct 21 00:26:05 2026 +0800
docs: add SyncedContextEnforcer and watcher notification on commit
---
docs/Enforcers.mdx | 1 +
docs/MultiThreading.mdx | 2 +-
docs/ProductionDeployment.mdx | 6 +++---
3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/docs/Enforcers.mdx b/docs/Enforcers.mdx
index c87f7ff5f..a4f982e7f 100644
--- a/docs/Enforcers.mdx
+++ b/docs/Enforcers.mdx
@@ -25,6 +25,7 @@ The following enforcers are available by language. If you
maintain a third-party
|
[SyncedEnforcer](https://github.com/apache/casbin/blob/master/enforcer_synced.go)
| Casbin | Extends `Enforcer` with synchronized access for
thread-safe operations.
|
|
[SyncedCachedEnforcer](https://github.com/apache/casbin/blob/master/enforcer_cached_synced.go)|
Casbin | Combines the caching features of `CachedEnforcer` with the
synchronization of `SyncedEnforcer`.
|
|
[ContextEnforcer](https://github.com/apache/casbin/blob/master/enforcer_context.go)
| Casbin | Implements the `IEnforcerContext` interface to provide
context-aware operations. Currently supports context for adapter operations
like `LoadPolicyCtx()`, `SavePolicyCtx()`, `AddPolicyCtx()`, and
`RemovePolicyCtx()`. This interface is designed for future expansion of context
support across additional Casbin operations.
|
+|
[SyncedContextEnforcer](https://github.com/apache/casbin/blob/master/enforcer_context_synced.go)
| Casbin | Combines the context-aware operations of `ContextEnforcer` with the
synchronization of `SyncedEnforcer`. Use it instead of `ContextEnforcer` when
the enforcer is shared by several goroutines. Available in versions after
v3.11.0. |
```mdx-code-block
</TabItem>
diff --git a/docs/MultiThreading.mdx b/docs/MultiThreading.mdx
index a7b69a379..18e82ffb7 100644
--- a/docs/MultiThreading.mdx
+++ b/docs/MultiThreading.mdx
@@ -6,7 +6,7 @@ keywords: [multi-threading]
authors: [hsluoyz]
---
-In **multi-threaded** code, use Casbin’s **synchronized enforcer** so one
enforcer can be shared safely across threads:
[SyncedEnforcer](https://github.com/apache/casbin/blob/master/enforcer_synced.go)
(Go),
[enforcer_synced.cpp](https://github.com/apache/casbin-cpp/blob/master/casbin/enforcer_synced.cpp)
(C++).
+In **multi-threaded** code, use Casbin’s **synchronized enforcer** so one
enforcer can be shared safely across threads:
[SyncedEnforcer](https://github.com/apache/casbin/blob/master/enforcer_synced.go)
and
[SyncedContextEnforcer](https://github.com/apache/casbin/blob/master/enforcer_context_synced.go)
(Go),
[enforcer_synced.cpp](https://github.com/apache/casbin-cpp/blob/master/casbin/enforcer_synced.cpp)
(C++).
The synced enforcer can also **auto-reload** policy: call
`StartAutoLoadPolicy()` to poll the policy source and reload when it changes;
call `StopAutoLoadPolicy()` to stop.
diff --git a/docs/ProductionDeployment.mdx b/docs/ProductionDeployment.mdx
index 64b046754..0c9148c2f 100644
--- a/docs/ProductionDeployment.mdx
+++ b/docs/ProductionDeployment.mdx
@@ -34,13 +34,13 @@ The plain `Enforcer` is **not** safe for concurrent use
when policy can change w
| Language | Synchronized enforcer |
|----------|-----------------------|
-| Go | `casbin.NewSyncedEnforcer()`, `casbin.NewSyncedCachedEnforcer()` |
+| Go | `casbin.NewSyncedEnforcer()`, `casbin.NewSyncedCachedEnforcer()`,
`casbin.NewSyncedContextEnforcer()` (for the `*Ctx` API, versions after
v3.11.0) |
| Java | `SyncedEnforcer`, `SyncedCachedEnforcer` |
| Python | `casbin.SyncedEnforcer` |
| Node.js | `newSyncedEnforcer()` |
| C++ | `casbin::SyncedEnforcer` |
-The synchronized enforcer has the same API as `Enforcer`. See
[Multithreading](/docs/multi-threading) and [Enforcers](/docs/enforcers) for
details.
+The synchronized enforcer has the same API as `Enforcer`. In Go,
`ContextEnforcer` is not synchronized either: concurrent `LoadPolicyCtx()` /
`AddPolicyCtx()` and `Enforce()` can crash the process with `concurrent map
read and map write`, so use `NewSyncedContextEnforcer()` instead (versions
after v3.11.0; in earlier versions guard it with your own `sync.RWMutex`). See
[Multithreading](/docs/multi-threading) and [Enforcers](/docs/enforcers) for
details.
## Cache decisions carefully
@@ -104,7 +104,7 @@ Two ways to keep them together:
enforcer.add_grouping_policy("alice", "team-admin")
```
-2. **Go: use the transactional enforcer.** `NewTransactionalEnforcer()` with a
transactional adapter (for example `gormadapter.NewTransactionalAdapterByDB()`)
buffers changes and applies them to the database and to memory on `Commit()`.
See [Adapters: Transaction](/docs/adapters#transaction). A commit does not
notify the watcher, so call `w.Update()` after it to tell the other instances.
+2. **Go: use the transactional enforcer.** `NewTransactionalEnforcer()` with a
transactional adapter (for example `gormadapter.NewTransactionalAdapterByDB()`)
buffers changes and applies them to the database and to memory on `Commit()`.
See [Adapters: Transaction](/docs/adapters#transaction). Versions after v3.11.0
notify the watcher once `Commit()` has succeeded, with the exact changes when
the watcher is a `WatcherEx`, and a rolled-back transaction notifies nobody. In
v3.11.0 and earli [...]
## Read-only replicas and migrations
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]