cache

package
v0.13.4 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(config ...Config) func(http.Handler) http.Handler

Cache the response of GET requests for a given duration. By default, it will use an in-memory cache with a duration of 3 seconds, with a maximum of 1000 entries. You can provide your own storage implementation by passing a Config struct to the middleware. You can also provide your own key function to generate the cache key for a given request. Headers can be used to invalidate the cache:

  • Cache-Control: no-cache will bypass the cache
  • Cache-Control: no-store might use the cache but will not store the response in the cache

Types

type Config

type Config struct {
	Storage Storage
	Key     func(r *http.Request) string // Key returns the cache key for the request
}

type MultiHTTPWriter

type MultiHTTPWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

MultiHTTPWriter is a http.ResponseWriter that writes the response to multiple writers

func (*MultiHTTPWriter) Unwrap

func (m *MultiHTTPWriter) Unwrap() http.ResponseWriter

func (*MultiHTTPWriter) Write

func (m *MultiHTTPWriter) Write(p []byte) (int, error)

func (*MultiHTTPWriter) WriteHeader

func (m *MultiHTTPWriter) WriteHeader(statusCode int)

type Storage

type Storage interface {
	Get(key string) (string, bool)
	Set(key string, value string)
}

type TTLCache

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

func NewInMemoryCache

func NewInMemoryCache(duration time.Duration, maxObjects int) *TTLCache

func (*TTLCache) Get

func (t *TTLCache) Get(key string) (string, bool)

func (*TTLCache) Set

func (t *TTLCache) Set(key string, value string)

Jump to

Keyboard shortcuts

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