Help us shape the future of Go! Take the 2026 Go Developer Survey

cache

package
v2.100.2 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSuchKey = errors.New("there's no such key existing in cache")

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Set puts key and value into cache.
	// First parameter for extra should be time.Time object denoting expected survival time.
	// If survival time equals 0 or less, the key will always be survival.
	Set(key string, value bool, extra ...interface{}) error

	// Get returns result for key,
	// If there's no such key existing in cache,
	// ErrNoSuchKey will be returned.
	Get(key string) (bool, error)

	// Delete will remove the specific key in cache.
	// If there's no such key existing in cache,
	// ErrNoSuchKey will be returned.
	Delete(key string) error

	// Clear deletes all the items stored in cache.
	Clear() error
}

func NewDefaultCache

func NewDefaultCache() (Cache, error)

func NewSyncCache

func NewSyncCache() (Cache, error)

type DefaultCache

type DefaultCache map[string]cacheItem

func (*DefaultCache) Clear

func (c *DefaultCache) Clear() error

func (*DefaultCache) Delete

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

func (*DefaultCache) Get

func (c *DefaultCache) Get(key string) (bool, error)

func (*DefaultCache) Set

func (c *DefaultCache) Set(key string, value bool, extra ...interface{}) error

type SyncCache

type SyncCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*SyncCache) Clear

func (c *SyncCache) Clear() error

func (*SyncCache) Delete

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

func (*SyncCache) Get

func (c *SyncCache) Get(key string) (bool, error)

func (*SyncCache) Set

func (c *SyncCache) Set(key string, value bool, extra ...interface{}) error

Jump to

Keyboard shortcuts

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