Closed seblaz closed 2 years ago
it isn't supported, cache properties are immutable.
Hi @nqv , I can concur with @seblaz .
In our use case, we have a common util to build the default cache, then allow others to customize with options.
func BuildResilientLoadingCache(loadfn cache.LoaderFunc, maxSize int, writeExpire time.Duration,
opts ...cache.Option) cache.LoadingCache {
options := append([]cache.Option{
cache.WithPolicy("tinylfu"),
cache.WithReloader(&ResilientReloader{Load: loadfn}),
cache.WithMaximumSize(maxSize),
cache.WithRefreshAfterWrite(writeExpire),
}, opts...)
c := cache.NewLoadingCache(
loadfn,
options...,
)
return c
}
But if we allow applying options to cache,
func BuildResilientLoadingCache(loadfn cache.LoaderFunc, maxSize int, writeExpire time.Duration,
opts ...cache.Option) cache.LoadingCache {
c := cache.NewLoadingCache(
loadfn,
cache.WithPolicy("tinylfu"),
cache.WithReloader(&ResilientReloader{Load: loadfn}),
cache.WithMaximumSize(maxSize),
cache.WithRefreshAfterWrite(writeExpire),
)
for _, opt := range opts {
opt(c)
}
return c
}
user can choose to further extend the cache with customized options if desirable.
Hi! It would be great if some properties of the cache could be changed after the creation, like the
MaximumSize
andExpireAfterWrite
, is that possible?