cache

package
v0.0.0-...-31c1c1e Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cacher

type Cacher interface {
	// Get returns the cached object under the key. It returns the object, its remaining
	// TTL. The returned interface is nil if of the object can't be found or it expired.
	// The error is non-nil if the object should be returned but can't due to some
	// implementation error.
	Get(key string) (interface{}, time.Duration, error)

	// Put adds an object under key to the cache. You have to provide its size. Any object
	// that may be stored under the same key will be overwritten.
	// The size parameter is a hint for how big this object is, whatever units
	// have been chosen for the MaxSize and MaxFileSize.
	// If the whole cache is bigger than the allowed size, the least used objects
	// will be removed until the cache size is lower than the allowed size.
	// A non-nil error is returned if the object couldn't be added to the cache.
	Put(key string, o interface{}, size uint64) error

	// Purge deletes the object stored under the key. A non-nil error is returned if
	// the object exists but can't be removed.
	Delete(key string) error

	// PurgeAll empties the whole cache.
	Purge()

	// TTL returns the cache's default TTL
	TTL() time.Duration

	// IsExtensionCacheable returns whether a file extension (e.g. .html) is allowed to be cached.
	IsExtensionCacheable(extension string) bool

	// IsSizeCacheable returns whether if a size is allowed to be cached.
	IsSizeCacheable(size uint64) bool
}

Cacher is an interface for a cache for arbitrary objects

func NewLRUCache

func NewLRUCache(config LRUConfig) (Cacher, error)

NewLRUCache returns an implementation of the Cacher interface that implements a LRU cache.

type LRUConfig

type LRUConfig struct {
	TTL         time.Duration // For how long the object should stay in cache
	MaxSize     uint64        // Max. size of the cache, 0 for unlimited, bytes
	MaxFileSize uint64        // Max. file size allowed to put in cache, 0 for unlimited, bytes
	Extensions  []string      // List of file extension allowed to cache, empty list for all files
	Logger      log.Logger
}

LRUConfig is the configuration for a new LRU cache

Jump to

Keyboard shortcuts

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