Documentation
¶
Overview ¶
Package middleware provides various middleware implementations for the hypercache service. This package includes logging middleware that wraps the hypercache service to provide execution time logging and method call tracing for debugging and monitoring purposes.
Package middleware provides various middleware implementations for the hypercache service. This package includes stats middleware that collects and reports cache operation statistics.
Index ¶
- func NewLoggingMiddleware(next hypercache.Service, logger Logger) hypercache.Service
- func NewStatsCollectorMiddleware(next hypercache.Service, statsCollector stats.ICollector) hypercache.Service
- type Logger
- type LoggingMiddleware
- func (mw LoggingMiddleware) Allocation() int64
- func (mw LoggingMiddleware) Capacity() int
- func (mw LoggingMiddleware) Clear(ctx context.Context) error
- func (mw LoggingMiddleware) Count(ctx context.Context) int
- func (mw LoggingMiddleware) Get(ctx context.Context, key string) (any, bool)
- func (mw LoggingMiddleware) GetMultiple(ctx context.Context, keys ...string) (map[string]any, map[string]error)
- func (mw LoggingMiddleware) GetOrSet(ctx context.Context, key string, value any, expiration time.Duration) (any, error)
- func (mw LoggingMiddleware) GetStats() stats.Stats
- func (mw LoggingMiddleware) GetWithInfo(ctx context.Context, key string) (*cache.Item, bool)
- func (mw LoggingMiddleware) List(ctx context.Context, filters ...backend.IFilter) ([]*cache.Item, error)
- func (mw LoggingMiddleware) Remove(ctx context.Context, keys ...string) error
- func (mw LoggingMiddleware) Set(ctx context.Context, key string, value any, expiration time.Duration) error
- func (mw LoggingMiddleware) Stop()
- func (mw LoggingMiddleware) TriggerEviction()
- type StatsCollectorMiddleware
- func (mw StatsCollectorMiddleware) Allocation() int64
- func (mw StatsCollectorMiddleware) Capacity() int
- func (mw StatsCollectorMiddleware) Clear(ctx context.Context) error
- func (mw StatsCollectorMiddleware) Count(ctx context.Context) int
- func (mw StatsCollectorMiddleware) Get(ctx context.Context, key string) (any, bool)
- func (mw StatsCollectorMiddleware) GetMultiple(ctx context.Context, keys ...string) (map[string]any, map[string]error)
- func (mw StatsCollectorMiddleware) GetOrSet(ctx context.Context, key string, value any, expiration time.Duration) (any, error)
- func (mw StatsCollectorMiddleware) GetStats() stats.Stats
- func (mw StatsCollectorMiddleware) GetWithInfo(ctx context.Context, key string) (*cache.Item, bool)
- func (mw StatsCollectorMiddleware) List(ctx context.Context, filters ...backend.IFilter) ([]*cache.Item, error)
- func (mw StatsCollectorMiddleware) Remove(ctx context.Context, keys ...string) error
- func (mw StatsCollectorMiddleware) Set(ctx context.Context, key string, value any, expiration time.Duration) error
- func (mw StatsCollectorMiddleware) Stop()
- func (mw StatsCollectorMiddleware) TriggerEviction()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewLoggingMiddleware ¶
func NewLoggingMiddleware(next hypercache.Service, logger Logger) hypercache.Service
NewLoggingMiddleware returns a new LoggingMiddleware.
func NewStatsCollectorMiddleware ¶
func NewStatsCollectorMiddleware(next hypercache.Service, statsCollector stats.ICollector) hypercache.Service
NewStatsCollectorMiddleware returns a new StatsCollectorMiddleware.
Types ¶
type Logger ¶
Logger describes a logging interface allowing to implement different external, or custom logger. Tested with logrus, and Uber's Zap (high-performance), but should work with any other logger that matches the interface.
type LoggingMiddleware ¶
type LoggingMiddleware struct {
// contains filtered or unexported fields
}
LoggingMiddleware is a middleware that logs the time it takes to execute the next middleware. Must implement the hypercache.Service interface.
func (LoggingMiddleware) Allocation ¶
func (mw LoggingMiddleware) Allocation() int64
Allocation returns the size allocation in bytes cache.
func (LoggingMiddleware) Capacity ¶
func (mw LoggingMiddleware) Capacity() int
Capacity takes to execute the next middleware.
func (LoggingMiddleware) Clear ¶
func (mw LoggingMiddleware) Clear(ctx context.Context) error
Clear logs the time it takes to execute the next middleware.
func (LoggingMiddleware) Count ¶
func (mw LoggingMiddleware) Count(ctx context.Context) int
Count takes to execute the next middleware.
func (LoggingMiddleware) GetMultiple ¶
func (mw LoggingMiddleware) GetMultiple(ctx context.Context, keys ...string) (map[string]any, map[string]error)
GetMultiple logs the time it takes to execute the next middleware.
func (LoggingMiddleware) GetOrSet ¶
func (mw LoggingMiddleware) GetOrSet(ctx context.Context, key string, value any, expiration time.Duration) (any, error)
GetOrSet logs the time it takes to execute the next middleware.
func (LoggingMiddleware) GetStats ¶
func (mw LoggingMiddleware) GetStats() stats.Stats
GetStats logs the time it takes to execute the next middleware.
func (LoggingMiddleware) GetWithInfo ¶
GetWithInfo logs the time it takes to execute the next middleware.
func (LoggingMiddleware) List ¶
func (mw LoggingMiddleware) List(ctx context.Context, filters ...backend.IFilter) ([]*cache.Item, error)
List logs the time it takes to execute the next middleware.
func (LoggingMiddleware) Remove ¶
func (mw LoggingMiddleware) Remove(ctx context.Context, keys ...string) error
Remove logs the time it takes to execute the next middleware.
func (LoggingMiddleware) Set ¶
func (mw LoggingMiddleware) Set(ctx context.Context, key string, value any, expiration time.Duration) error
Set logs the time it takes to execute the next middleware.
func (LoggingMiddleware) Stop ¶
func (mw LoggingMiddleware) Stop()
Stop logs the time it takes to execute the next middleware.
func (LoggingMiddleware) TriggerEviction ¶
func (mw LoggingMiddleware) TriggerEviction()
TriggerEviction logs the time it takes to execute the next middleware.
type StatsCollectorMiddleware ¶
type StatsCollectorMiddleware struct {
// contains filtered or unexported fields
}
StatsCollectorMiddleware is a middleware that collects stats. It can and should re-use the same stats collector as the hypercache. Must implement the hypercache.Service interface.
func (StatsCollectorMiddleware) Allocation ¶
func (mw StatsCollectorMiddleware) Allocation() int64
Allocation returns the size allocation in bytes cache.
func (StatsCollectorMiddleware) Capacity ¶
func (mw StatsCollectorMiddleware) Capacity() int
Capacity returns the capacity of the cache.
func (StatsCollectorMiddleware) Clear ¶
func (mw StatsCollectorMiddleware) Clear(ctx context.Context) error
Clear collects stats for the Clear method.
func (StatsCollectorMiddleware) Count ¶
func (mw StatsCollectorMiddleware) Count(ctx context.Context) int
Count returns the count of the items in the cache.
func (StatsCollectorMiddleware) GetMultiple ¶
func (mw StatsCollectorMiddleware) GetMultiple(ctx context.Context, keys ...string) (map[string]any, map[string]error)
GetMultiple collects stats for the GetMultiple method.
func (StatsCollectorMiddleware) GetOrSet ¶
func (mw StatsCollectorMiddleware) GetOrSet(ctx context.Context, key string, value any, expiration time.Duration) (any, error)
GetOrSet collects stats for the GetOrSet method.
func (StatsCollectorMiddleware) GetStats ¶
func (mw StatsCollectorMiddleware) GetStats() stats.Stats
GetStats returns the stats of the cache.
func (StatsCollectorMiddleware) GetWithInfo ¶
GetWithInfo collects stats for the GetWithInfo method.
func (StatsCollectorMiddleware) List ¶
func (mw StatsCollectorMiddleware) List(ctx context.Context, filters ...backend.IFilter) ([]*cache.Item, error)
List collects stats for the List method.
func (StatsCollectorMiddleware) Remove ¶
func (mw StatsCollectorMiddleware) Remove(ctx context.Context, keys ...string) error
Remove collects stats for the Remove method.
func (StatsCollectorMiddleware) Set ¶
func (mw StatsCollectorMiddleware) Set(ctx context.Context, key string, value any, expiration time.Duration) error
Set collects stats for the Set method.
func (StatsCollectorMiddleware) Stop ¶
func (mw StatsCollectorMiddleware) Stop()
Stop collects the stats for Stop methods and stops the cache and all its goroutines (if any).
func (StatsCollectorMiddleware) TriggerEviction ¶
func (mw StatsCollectorMiddleware) TriggerEviction()
TriggerEviction triggers the eviction of the cache.