Zum Hauptinhalt springen

Enforcers

The Enforcer is Casbin’s main interface: you use it to enforce policy and to read or update policies and models.

Available enforcers

The following enforcers are available by language. If you maintain a third-party enforcer, we can add it to this list.

EnforcerAutorBeschreibung
EnforcerCasbinThe base Enforcer provides the primary interface for policy and model operations. See the Management API documentation for detailed API information.
CachedEnforcerCasbinExtends the Enforcer with in-memory caching of enforcement results. Supports configurable cache expiration and includes thread-safe access via read-write locks. Use EnableCache to toggle caching (enabled by default). The remaining API methods match those of the base Enforcer.
DistributedEnforcerCasbinDesigned for distributed deployments, this enforcer wraps SyncedEnforcer to work with dispatchers. Additional information is available in the dispatcher documentation.
SyncedEnforcerCasbinExtends Enforcer with synchronized access for thread-safe operations.
SyncedCachedEnforcerCasbinCombines the caching features of CachedEnforcer with the synchronization of SyncedEnforcer.
ContextEnforcerCasbinImplements 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.