cache

package
v2.0.7-beta.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// For use with functions that take an expiration time.
	NoExpiration time.Duration = -1

	// For use with functions that take an expiration time. Equivalent to
	// passing in the same expiration duration as was given to New() or
	// NewFrom() when the cache was created (e.g. 5 minutes.)
	DefaultExpiration time.Duration = 0

	// For use with functions that do not clean up.
	NoCleanup time.Duration = -1
)
View Source
const (
	// CertifyCacheDirName is dir name of certify cache.
	CertifyCacheDirName = "certs"
)

Variables

This section is empty.

Functions

func NewCertifyMutliCache added in v2.0.6

func NewCertifyMutliCache(caches ...certify.Cache) certify.Cache

NewCertifyMutliCache returns a certify.Cache with multiple caches Such as, cache.NewCertifyMutliCache(certify.NewMemCache(), certify.DirCache("certs")) This multiple cache will get certs from mem cache first, then dir cache to avoid read from filesystem every times.

Types

type Cache

type Cache interface {
	Set(k string, x any, d time.Duration)
	SetDefault(k string, x any)
	Add(k string, x any, d time.Duration) error
	Get(k string) (any, bool)
	GetWithExpiration(k string) (any, time.Time, bool)
	Delete(k string)
	DeleteExpired()
	Keys() []string
	OnEvicted(f func(string, any))
	Save(w io.Writer) (err error)
	SaveFile(fname string) error
	Load(r io.Reader) error
	LoadFile(fname string) error
	Items() map[string]Item
	ItemCount() int
	Flush()
}

func New

func New(defaultExpiration, cleanupInterval time.Duration) Cache

Return a new cache with a given default expiration duration and cleanup interval. If the expiration duration is less than one (or NoExpiration), the items in the cache never expire (by default), and must be deleted manually. If the cleanup interval is less than one, expired items are not deleted from the cache before calling c.DeleteExpired().

type Item

type Item struct {
	Object     any
	Expiration int64
}

func (Item) Expired

func (item Item) Expired() bool

Returns true if the item has expired.

Jump to

Keyboard shortcuts

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