echo_http_cache

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2023 License: MIT Imports: 20 Imported by: 1

README

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultCacheConfig defines default values for CacheConfig
	DefaultCacheConfig = CacheConfig{
		Skipper:    middleware.DefaultSkipper,
		Expiration: 3 * time.Minute,
	}
)
View Source
var DefaultCacheMemoryStoreConfig = CacheMemoryStoreConfig{
	Capacity:  10,
	Algorithm: LRU,
}

DefaultCacheMemoryStoreConfig provides default configuration values for CacheMemoryStoreConfig

Functions

func Cache

func Cache(store CacheStore) echo.MiddlewareFunc

Cache returns a cache middleware

e := echo.New()

... 추가 설명

func CacheWithConfig

func CacheWithConfig(config CacheConfig) echo.MiddlewareFunc

CacheWithConfig returns a cache middleware

Types

type Algorithm

type Algorithm string

Algorithm is the string type for caching algorithms labels.

const (
	// LRU is the constant for Least Recently Used.
	LRU Algorithm = "LRU"

	// MRU is the constant for Most Recently Used.
	MRU Algorithm = "MRU"

	// LFU is the constant for Least Frequently Used.
	LFU Algorithm = "LFU"

	// MFU is the constant for Most Frequently Used.
	MFU Algorithm = "MFU"
)

type CacheConfig

type CacheConfig struct {
	// Skipper defines a function to skip middleware.
	Skipper middleware.Skipper

	Store CacheStore

	Expiration                 time.Duration // default expiration
	IncludePaths               []string
	IncludePathsWithExpiration map[string]time.Duration // key: path, value: expiration //IncludePathsWithExpiration has higher priority
	ExcludePaths               []string
}

CacheConfig data structure for HTTP cache middleware.

type CacheMemoryStore

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

CacheMemoryStore is the built-in store implementation for Cache

func NewCacheMemoryStore

func NewCacheMemoryStore() (store *CacheMemoryStore)

func NewCacheMemoryStoreWithConfig

func NewCacheMemoryStoreWithConfig(config CacheMemoryStoreConfig) (store *CacheMemoryStore)

func (*CacheMemoryStore) Get

func (store *CacheMemoryStore) Get(key uint64) ([]byte, bool)

Get implements the cache Adapter interface Get method.

func (*CacheMemoryStore) Release

func (store *CacheMemoryStore) Release(key uint64)

Release implements the Adapter interface Release method.

func (*CacheMemoryStore) Set

func (store *CacheMemoryStore) Set(key uint64, response []byte, _ time.Time)

Set implements the cache Adapter interface Set method.

type CacheMemoryStoreConfig

type CacheMemoryStoreConfig struct {
	Capacity  int
	Algorithm Algorithm
}

CacheMemoryStoreConfig represents configuration for CacheMemoryStoreConfig

type CacheRedisClusterStore

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

CacheRedisClusterStore is the redis cluster store

func (*CacheRedisClusterStore) Get

func (store *CacheRedisClusterStore) Get(key uint64) ([]byte, bool)

Get implements the cache CacheRedisClusterStore interface Get method.

func (*CacheRedisClusterStore) Release

func (store *CacheRedisClusterStore) Release(key uint64)

Release implements the cache CacheRedisClusterStore interface Release method.

func (*CacheRedisClusterStore) Set

func (store *CacheRedisClusterStore) Set(key uint64, response []byte, expiration time.Time)

Set implements the cache CacheRedisClusterStore interface Set method.

type CacheRedisStore

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

CacheRedisStore is the redis standalone store implementation for Cache

func (*CacheRedisStore) Get

func (store *CacheRedisStore) Get(key uint64) ([]byte, bool)

Get implements the cache CacheRedisClusterStore interface Get method.

func (*CacheRedisStore) Release

func (store *CacheRedisStore) Release(key uint64)

func (*CacheRedisStore) Set

func (store *CacheRedisStore) Set(key uint64, response []byte, expiration time.Time)

type CacheResponse

type CacheResponse struct {
	// URL is URL
	URL string `json:"url"`

	// Header is the cached response header.
	Header http.Header `json:"header"`

	// Body is the cached response value.
	Body []byte `json:"body"`

	// Expiration is the cached response Expiration date.
	Expiration time.Time `json:"expiration"`

	// LastAccess is the last date a cached response was accessed.
	// Used by LRU and MRU algorithms.
	LastAccess time.Time `json:"lastAccess"`

	// Frequency is the count of times a cached response is accessed.
	// Used for LFU and MFU algorithms.
	Frequency int `json:"frequency"`
}

CacheResponse is the cached response data structure.

type CacheStore

type CacheStore interface {
	// Get retrieves the cached response by a given key. It also
	// returns true or false, whether it exists or not.
	Get(key uint64) ([]byte, bool)

	// Set caches a response for a given key until an Expiration date.
	Set(key uint64, response []byte, expiration time.Time)

	// Release frees cache for a given key.
	Release(key uint64)
}

CacheStore is the interface to be implemented by custom stores.

func NewCacheRedisClusterWithConfig

func NewCacheRedisClusterWithConfig(opt redis.RingOptions) CacheStore

NewCacheRedisClusterWithConfig initializes Redis adapter.

func NewCacheRedisStoreWithConfig

func NewCacheRedisStoreWithConfig(opt redis.Options) CacheStore

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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