MCPcopy
hub / github.com/apache/casbin / Enforce

Method Enforce

enforcer_cached_synced.go:60–83  ·  view source on GitHub ↗

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.

(rvals ...interface{})

Source from the content-addressed store, hash-verified

58// Enforce decides whether a "subject" can access a "object" with the operation "action", input parameters are usually: (sub, obj, act).
59// if rvals is not string , ignore the cache.
60func (e *SyncedCachedEnforcer) Enforce(rvals ...interface{}) (bool, error) {
61 if atomic.LoadInt32(&e.enableCache) == 0 {
62 return e.SyncedEnforcer.Enforce(rvals...)
63 }
64
65 key, ok := e.getKey(rvals...)
66 if !ok {
67 return e.SyncedEnforcer.Enforce(rvals...)
68 }
69
70 if res, err := e.getCachedResult(key); err == nil {
71 return res, nil
72 } else if err != cache.ErrNoSuchKey {
73 return res, err
74 }
75
76 res, err := e.SyncedEnforcer.Enforce(rvals...)
77 if err != nil {
78 return false, err
79 }
80
81 err = e.setCachedResult(key, res, e.expireTime)
82 return res, err
83}
84
85func (e *SyncedCachedEnforcer) LoadPolicy() error {
86 if atomic.LoadInt32(&e.enableCache) != 0 {

Callers

nothing calls this directly

Calls 4

getKeyMethod · 0.95
getCachedResultMethod · 0.95
setCachedResultMethod · 0.95
EnforceMethod · 0.65

Tested by

no test coverage detected