middleware

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2023 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

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.Collector) hypercache.Service

NewStatsCollectorMiddleware returns a new StatsCollectorMiddleware

Types

type Logger

type Logger interface {
	Infof(format string, v ...interface{})
	Errorf(format string, v ...interface{})
}

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) Capacity

func (mw LoggingMiddleware) Capacity() int

Capacity logs the time it takes to execute the next middleware.

func (LoggingMiddleware) Clear

func (mw LoggingMiddleware) Clear() error

Clear logs the time it takes to execute the next middleware.

func (LoggingMiddleware) Get

func (mw LoggingMiddleware) Get(key string) (value interface{}, ok bool)

Get logs the time it takes to execute the next middleware.

func (LoggingMiddleware) GetMultiple

func (mw LoggingMiddleware) GetMultiple(keys ...string) (result map[string]any, failed map[string]error)

GetMultiple logs the time it takes to execute the next middleware.

func (LoggingMiddleware) GetOrSet

func (mw LoggingMiddleware) GetOrSet(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) List

func (mw LoggingMiddleware) List(filters ...any) ([]*models.Item, error)

List logs the time it takes to execute the next middleware.

func (LoggingMiddleware) Remove

func (mw LoggingMiddleware) Remove(keys ...string)

Remove logs the time it takes to execute the next middleware.

func (LoggingMiddleware) Set

func (mw LoggingMiddleware) Set(key string, value any, expiration time.Duration) error

Set logs the time it takes to execute the next middleware.

func (LoggingMiddleware) Size

func (mw LoggingMiddleware) Size() int

Size 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) Capacity

func (mw StatsCollectorMiddleware) Capacity() int

Capacity returns the capacity of the cache

func (StatsCollectorMiddleware) Clear

func (mw StatsCollectorMiddleware) Clear() error

Clear collects stats for the Clear method.

func (StatsCollectorMiddleware) Get

func (mw StatsCollectorMiddleware) Get(key string) (interface{}, bool)

Get

func (StatsCollectorMiddleware) GetMultiple

func (mw StatsCollectorMiddleware) GetMultiple(keys ...string) (result map[string]any, failed map[string]error)

GetMultiple collects stats for the GetMultiple method.

func (StatsCollectorMiddleware) GetOrSet

func (mw StatsCollectorMiddleware) GetOrSet(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) List

func (mw StatsCollectorMiddleware) List(filters ...any) ([]*models.Item, error)

List collects stats for the List method.

func (StatsCollectorMiddleware) Remove

func (mw StatsCollectorMiddleware) Remove(keys ...string)

Remove collects stats for the Remove method.

func (StatsCollectorMiddleware) Set

func (mw StatsCollectorMiddleware) Set(key string, value any, expiration time.Duration) error

Set collects stats for the Set method.

func (StatsCollectorMiddleware) Size

func (mw StatsCollectorMiddleware) Size() int

Size returns the size of the cache

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL