Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var WithExpiration = func(callback func(result interface{}) time.Duration) Option { return &ExpirationOption{Callback: callback} }
WithExpiration returns an Option that sets a dynamic expiration time for cached results. The provided callback function is called with the result of the memoized function and should return a time.Duration indicating how long the result should be cached.
Example usage:
memoizer.Memoize("key", myFunc, memoizer.WithExpiration(func(result interface{}) time.Duration {
// Custom logic to determine expiration based on the result
return time.Hour
}))
Functions ¶
This section is empty.
Types ¶
type ExpirationOption ¶ added in v1.0.2
ExpirationOption is a struct that implements the Option interface. It contains a Callback function that determines the expiration duration for a cached result based on the result itself.
type Memoizer ¶
type Memoizer[T any] struct { // contains filtered or unexported fields }
Memoizer is a structure that provides memoization capabilities. It stores results of expensive function calls and returns the cached result when possible.
func NewMemoizer ¶
NewMemoizer creates and returns a new instance of a Memoizer.
func NewMemoizerWithCacheExpiration ¶
NewMemoizerWithCacheExpiration creates and returns a new instance of a Memoizer with a specified cache expiration time.