155
}
156
157
>
timeSource := opts.TimeSource
lru.go
158
>
if timeSource == nil {
159
timeSource = clock.NewRealTimeSource()
160
}
161
162
>
metrics.CacheSize.With(handler).Record(float64(maxSize))
lru.go
163
>
metrics.CacheTtl.With(handler).Record(opts.TTL)
164
>
c := &lru{
165
>
byAccess: list.New(),
166
>
byKey: make(map[any]*list.Element),
167
>
ttl: opts.TTL,
168
>
maxSize: maxSize,
169
>
currSize: 0,
170
>
pin: opts.Pin,
171
>
onPut: opts.OnPut,
172
>
onEvict: opts.OnEvict,
173
>
timeSource: timeSource,
174
>
metricsHandler: handler,
175
>
backgroundEvict: backgroundEvict,
176
>
}
177
>
if c.backgroundEvict().Enabled {
178
c.loops.Go(c.bgEvictLoop)
179
}
181
}
182