cache

package
v15.0.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

func New

func New(expirationCheckPeriod time.Duration) *Cache

func (*Cache) EvictExpiredEntries

func (c *Cache) EvictExpiredEntries()

func (*Cache) GetOrCreateCacheEntry

func (c *Cache) GetOrCreateCacheEntry(key interface{}) *Entry

type CacheWithErr

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

func NewWithError

func NewWithError(ttl, errTtl time.Duration, errCacheStrategy ErrCacheStrategy) *CacheWithErr

func (*CacheWithErr) GetItem

func (c *CacheWithErr) GetItem(ctx context.Context, key interface{}, f GetItemDirectly) (interface{}, error)

type Entry

type Entry struct {

	// Expires holds the time when this entry should be removed from the cache.
	Expires time.Time
	// Item is the cached item.
	Item interface{}
	// contains filtered or unexported fields
}

func (*Entry) IsEmptyLocked

func (e *Entry) IsEmptyLocked() bool

func (*Entry) IsExpiredLocked

func (e *Entry) IsExpiredLocked(t time.Time) bool

func (*Entry) IsNeedRefreshLocked

func (e *Entry) IsNeedRefreshLocked() bool

func (Entry) Lock

func (m Entry) Lock(ctx context.Context) bool

func (Entry) TryLock

func (m Entry) TryLock() bool

func (Entry) Unlock

func (m Entry) Unlock()

type EntryWithErr

type EntryWithErr struct {
	// Item is the cached item.
	Item interface{}
	Err  error
}

type ErrCacheStrategy

type ErrCacheStrategy func(error) bool

ErrCacheStrategy determines whether an error is cacheable or not. Returns true if cacheable and false otherwise.

type GetItemDirectly

type GetItemDirectly func() (interface{}, error)

Jump to

Keyboard shortcuts

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