Also use SimpleCache in cache.HTTPClient

This commit is contained in:
Deluan
2024-06-21 17:40:18 -04:00
parent 29bc17acd7
commit 29b7b740ce
3 changed files with 67 additions and 25 deletions
+11 -1
View File
@@ -14,9 +14,19 @@ type SimpleCache[V any] interface {
Keys() []string
}
func NewSimpleCache[V any]() SimpleCache[V] {
type Options struct {
SizeLimit int
DefaultTTL time.Duration
}
func NewSimpleCache[V any](options ...Options) SimpleCache[V] {
c := ttlcache.NewCache()
c.SkipTTLExtensionOnHit(true)
if len(options) > 0 {
c.SetCacheSizeLimit(options[0].SizeLimit)
_ = c.SetTTL(options[0].DefaultTTL)
}
return &simpleCache[V]{
data: c,
}