mirror of
https://github.com/kemko/reproxy.git
synced 2026-01-04 09:15:50 +03:00
Bumps the go-modules-updates group with 2 updates: [github.com/didip/tollbooth/v7](https://github.com/didip/tollbooth) and [golang.org/x/crypto](https://github.com/golang/crypto). Updates `github.com/didip/tollbooth/v7` from 7.0.1 to 7.0.2 - [Commits](https://github.com/didip/tollbooth/compare/v7.0.1...v7.0.2) Updates `golang.org/x/crypto` from 0.23.0 to 0.24.0 - [Commits](https://github.com/golang/crypto/compare/v0.23.0...v0.24.0) --- updated-dependencies: - dependency-name: github.com/didip/tollbooth/v7 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules-updates - dependency-name: golang.org/x/crypto dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules-updates ... Signed-off-by: dependabot[bot] <support@github.com>
37 lines
1.0 KiB
Go
37 lines
1.0 KiB
Go
package cache
|
|
|
|
import "time"
|
|
|
|
type options[K comparable, V any] interface {
|
|
WithTTL(ttl time.Duration) Cache[K, V]
|
|
WithMaxKeys(maxKeys int) Cache[K, V]
|
|
WithLRU() Cache[K, V]
|
|
WithOnEvicted(fn func(key K, value V)) Cache[K, V]
|
|
}
|
|
|
|
// WithTTL functional option defines TTL for all cache entries.
|
|
// By default, it is set to 10 years, sane option for expirable cache might be 5 minutes.
|
|
func (c *cacheImpl[K, V]) WithTTL(ttl time.Duration) Cache[K, V] {
|
|
c.ttl = ttl
|
|
return c
|
|
}
|
|
|
|
// WithMaxKeys functional option defines how many keys to keep.
|
|
// By default, it is 0, which means unlimited.
|
|
func (c *cacheImpl[K, V]) WithMaxKeys(maxKeys int) Cache[K, V] {
|
|
c.maxKeys = maxKeys
|
|
return c
|
|
}
|
|
|
|
// WithLRU sets cache to LRU (Least Recently Used) eviction mode.
|
|
func (c *cacheImpl[K, V]) WithLRU() Cache[K, V] {
|
|
c.isLRU = true
|
|
return c
|
|
}
|
|
|
|
// WithOnEvicted defined function which would be called automatically for automatically and manually deleted entries
|
|
func (c *cacheImpl[K, V]) WithOnEvicted(fn func(key K, value V)) Cache[K, V] {
|
|
c.onEvicted = fn
|
|
return c
|
|
}
|