cachemw

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRequestHash

func GenerateRequestHash(req *http.Request) (string, error)

Types

type Cache

type Cache interface {
	Get(ctx context.Context, key string) ([]byte, error)
	Set(ctx context.Context, key string, value []byte) error
}

type CacheMiddleware

type CacheMiddleware struct {
	// contains filtered or unexported fields
}

func New

func New(cache Cache, opts ...Option) *CacheMiddleware

func (*CacheMiddleware) RoundTripper

func (m *CacheMiddleware) RoundTripper(next http.RoundTripper) http.RoundTripper

type CacheWithTTL

type CacheWithTTL interface {
	Cache
	SetWithTTL(ctx context.Context, key string, value []byte, ttl time.Duration) error
}

type KeyGenerator

type KeyGenerator interface {
	Key(req *http.Request) (string, error)
}

KeyGenerator is an interface that defines a method for generating a cache key based on an HTTP request. If a Cache implementation also implements this interface, the CacheMiddleware will use the Key method to generate cache keys.

type Option

type Option func(*CacheMiddleware)

func WithCacheableReq

func WithCacheableReq(f func(req *http.Request) bool) Option

WithCacheableReq is an option function that sets a custom function to determine if a request is cacheable. The provided function `f` takes an *http.Request and returns a boolean indicating whether the request should be cached.

func WithTTL

func WithTTL(ttl time.Duration) Option

WithTTL sets the time-to-live (TTL) duration for the cache middleware. The TTL determines how long cached items should be retained before they expire.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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