NewInMemoryCache returns a new in-memory cache on top of the given fetcher. Successful responses are valid for the duration of successTTL, unsuccessful responses are valid for the duration of errorTTL.
(fetcher Fetcher, successTTL, errorTTL time.Duration)
| 106 | // Successful responses are valid for the duration of successTTL, unsuccessful |
| 107 | // responses are valid for the duration of errorTTL. |
| 108 | func NewInMemoryCache(fetcher Fetcher, successTTL, errorTTL time.Duration) Fetcher { |
| 109 | return &inMemoryCache{ |
| 110 | Fetcher: fetcher, |
| 111 | successTTL: successTTL, |
| 112 | errorTTL: errorTTL, |
| 113 | lastCleanup: now(), |
| 114 | authInfo: make(map[cachedReq]*cachedAuthInfoRes), |
| 115 | applicationRights: make(map[cachedReq]*cachedRes), |
| 116 | clientRights: make(map[cachedReq]*cachedRes), |
| 117 | gatewayRights: make(map[cachedReq]*cachedRes), |
| 118 | organizationRights: make(map[cachedReq]*cachedRes), |
| 119 | userRights: make(map[cachedReq]*cachedRes), |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | type inMemoryCache struct { |
| 124 | Fetcher |