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

Method Enforce

enforcer_cached.go:65–88  ·  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

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

Calls 4

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