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{})
| 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. |
| 60 | func (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 | |
| 85 | func (e *SyncedCachedEnforcer) LoadPolicy() error { |
| 86 | if atomic.LoadInt32(&e.enableCache) != 0 { |
nothing calls this directly
no test coverage detected