cache

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package cache implements middleware for response caching. Request's component used as a key.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeyFunc

func KeyFunc(fn func(r *http.Request) string) func(m *Middleware)

KeyFunc defines custom caching key function

func KeyWithBody

func KeyWithBody(m *Middleware)

KeyWithBody makes whole body to be a part of the caching key

func KeyWithHeaders

func KeyWithHeaders(m *Middleware)

KeyWithHeaders makes all headers to affect caching key

func KeyWithHeadersExcluded

func KeyWithHeadersExcluded(headers ...string) func(m *Middleware)

KeyWithHeadersExcluded make all headers, except passed in to affect caching key

func KeyWithHeadersIncluded

func KeyWithHeadersIncluded(headers ...string) func(m *Middleware)

KeyWithHeadersIncluded allows some headers to affect caching key

func Methods

func Methods(methods ...string) func(m *Middleware)

Methods sets what HTTP methods allowed to be cached, default is "GET" only

Types

type Middleware

type Middleware struct {
	Service
	// contains filtered or unexported fields
}

Middleware for caching responses. The key cache generated from request.

func New

func New(svc Service, opts ...func(m *Middleware)) *Middleware

New makes cache middleware for given cache.Service and optional set of params By default allowed methods limited to GET only and key for request's URL

func (*Middleware) Middleware

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

Middleware is the middleware wrapper injecting external cache.Service (LoadingCache) into the call chain. Key extracted from the request and options defines what part of request should be used for key and what method are allowed for caching.

type Service

type Service interface {
	Get(key string, fn func() (interface{}, error)) (interface{}, error)
}

Service defines loading cache interface to be used for caching, matching github.com/go-pkgz/lcw interface

type ServiceFunc

type ServiceFunc func(key string, fn func() (interface{}, error)) (interface{}, error)

ServiceFunc is an adapter to allow the use of an ordinary functions as the loading cache.

func (ServiceFunc) Get

func (c ServiceFunc) Get(key string, fn func() (interface{}, error)) (interface{}, error)

Get and/or fill the cached value for a given keyDbg

Jump to

Keyboard shortcuts

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