Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MemoizeWithInvalidate ¶ added in v0.1.34
MemoizeWithInvalidate wraps a function with a caching layer that stores and reuses computed results. It returns two values:
- A memoized version of the input function with identical signature
- An invalidation function that clears the cache when called
The memoized function caches results based on the string representation of input arguments. Cache entries expire based on time and size limits set via options.
Options:
- WithMaxSize: Sets maximum number of cached results (default 100)
- WithExpiration: Sets how long cached results remain valid (default 1 hour)
- WithIgnoreParams: Specifies argument indices to exclude from cache key
- WithMemoizeErrors: Controls whether error results are cached (default false)
- WithMetrics: Provides a collector for cache performance metrics
Example:
memoizedFn, invalidate := Memoize(expensiveFunc, WithMaxSize(1000)) result := memoizedFn(arg) // Result is computed and cached invalidate() // Clears the cache
Types ¶
type MemoMetrics ¶ added in v0.1.14
type MetricsCollector ¶ added in v0.1.17
type MetricsCollector interface { Setup(function interface{}) Collect(metrics *MemoMetrics) }
type Option ¶ added in v0.1.14
type Option func(*memoizeOptions)
func WithExpiration ¶
func WithIgnoreParams ¶ added in v0.1.23
func WithMaxSize ¶
func WithMemoizeErrors ¶ added in v0.1.33
func WithMetrics ¶ added in v0.1.17
func WithMetrics(collector MetricsCollector) Option
type PrometheusMetricsCollector ¶ added in v0.1.17
type PrometheusMetricsCollector struct {
// contains filtered or unexported fields
}
func NewPrometheusMetricsCollector ¶ added in v0.1.17
func NewPrometheusMetricsCollector(labels ...string) *PrometheusMetricsCollector
func (*PrometheusMetricsCollector) Collect ¶ added in v0.1.17
func (p *PrometheusMetricsCollector) Collect(metrics *MemoMetrics)
func (*PrometheusMetricsCollector) Setup ¶ added in v0.1.17
func (p *PrometheusMetricsCollector) Setup(function interface{})
Click to show internal directories.
Click to hide internal directories.