NewEnforcer constructs the production enforcer. cacheTTL of 0 disables the cache (every Get hits the DB) — useful for tests that mutate account_limits and want immediate visibility.
(store *Store, counter Counter, defaults Defaults, cacheTTL time.Duration)
| 55 | // the cache (every Get hits the DB) — useful for tests that mutate |
| 56 | // account_limits and want immediate visibility. |
| 57 | func NewEnforcer(store *Store, counter Counter, defaults Defaults, cacheTTL time.Duration) *DBEnforcer { |
| 58 | return &DBEnforcer{ |
| 59 | store: store, |
| 60 | counter: counter, |
| 61 | defaults: defaults, |
| 62 | cacheTTL: cacheTTL, |
| 63 | cache: make(map[string]cachedLimits), |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | // newEnforcerWithReader is the test seam: lets unit tests inject a fake |
| 68 | // limitsReader so they don't need a Postgres pool. |