MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / maybeCleanup

Method maybeCleanup

pkg/auth/rights/cache.go:138–174  ·  view source on GitHub ↗

maybeCleanup cleans up expired results if necessary.

()

Source from the content-addressed store, hash-verified

136
137// maybeCleanup cleans up expired results if necessary.
138func (f *inMemoryCache) maybeCleanup() {
139 cleanupTTL := max(f.errorTTL, f.successTTL)
140 if now().Sub(f.lastCleanup) <= cleanupTTL*10 {
141 return
142 }
143 for req, res := range f.authInfo {
144 if !res.valid(f.successTTL, f.errorTTL) {
145 delete(f.authInfo, req)
146 }
147 }
148 for req, res := range f.applicationRights {
149 if !res.valid(f.successTTL, f.errorTTL) {
150 delete(f.applicationRights, req)
151 }
152 }
153 for req, res := range f.clientRights {
154 if !res.valid(f.successTTL, f.errorTTL) {
155 delete(f.clientRights, req)
156 }
157 }
158 for req, res := range f.gatewayRights {
159 if !res.valid(f.successTTL, f.errorTTL) {
160 delete(f.gatewayRights, req)
161 }
162 }
163 for req, res := range f.organizationRights {
164 if !res.valid(f.successTTL, f.errorTTL) {
165 delete(f.organizationRights, req)
166 }
167 }
168 for req, res := range f.userRights {
169 if !res.valid(f.successTTL, f.errorTTL) {
170 delete(f.userRights, req)
171 }
172 }
173 f.lastCleanup = now()
174}
175
176func (f *inMemoryCache) AuthInfo(ctx context.Context) (authInfo *ttnpb.AuthInfoResponse, err error) {
177 defer func() { registerAuthInfoRequest(ctx, authInfo, err) }()

Callers 7

AuthInfoMethod · 0.95
ApplicationRightsMethod · 0.95
ClientRightsMethod · 0.95
GatewayRightsMethod · 0.95
OrganizationRightsMethod · 0.95
UserRightsMethod · 0.95
MaybeCleanupTestMethod · 0.95

Calls 3

nowFunction · 0.85
SubMethod · 0.80
validMethod · 0.45

Tested by 1

MaybeCleanupTestMethod · 0.76