cache

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: BSD-1-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ShortExpiration   = time.Second * 10
	MedExpiration     = time.Second * 60
	LongExpiration    = time.Hour
	DefaultExpiration = MedExpiration
)
View Source
const (
	ErrNotFound cacheError = iota
	ErrInvalidKey
	ErrInvalidValue
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheItem

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

func NewCacheItem

func NewCacheItem(key string, value interface{}, ttl time.Duration) *CacheItem

func (*CacheItem) TTL

func (c *CacheItem) TTL() time.Duration

func (*CacheItem) Value

func (c *CacheItem) Value() interface{}

type InMemoryCache

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

func NewInMemoryCache

func NewInMemoryCache(cleanInterval time.Duration) *InMemoryCache

func (*InMemoryCache) Clear

func (c *InMemoryCache) Clear() error

Clear the cache.

func (*InMemoryCache) Connect

func (c *InMemoryCache) Connect() error

Connect to the cache.

func (*InMemoryCache) Delete

func (c *InMemoryCache) Delete(key string) error

Delete an item from the cache.

func (*InMemoryCache) Get

func (c *InMemoryCache) Get(key string, dst any) (client.Item, error)

Get an item from the cache.

func (*InMemoryCache) Has

func (c *InMemoryCache) Has(key string) (bool, error)

Check if the cache has an item.

func (*InMemoryCache) Keys

func (c *InMemoryCache) Keys() ([]string, error)

Keys returns all keys in the cache.

func (*InMemoryCache) Set

func (c *InMemoryCache) Set(key string, value any, ttl time.Duration) error

Set an item in the cache.

Jump to

Keyboard shortcuts

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