cache

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 10 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Cache

Installation

Install Cache
go get -u github.com/gowool/cache
Install Fx Module
go get -u github.com/gowool/cache/fx
Install Redis Backend
go get -u github.com/gowool/rediscachebe

License

Distributed under MIT License, please see license file within the code for more details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = freecache.ErrNotFound

Functions

This section is empty.

Types

type Backend

type Backend interface {
	Get(ctx context.Context, key string) ([]byte, error)
	Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
	Del(ctx context.Context, key string) error
	DelAll(ctx context.Context) error
}

type Cache

type Cache interface {
	Set(ctx context.Context, key string, value any, tags ...string) error
	Get(ctx context.Context, key string, value any) error
	DelByKey(ctx context.Context, key string) error
	DelByTag(ctx context.Context, tag string) error
	DelAll(ctx context.Context) error
}

func NewCache

func NewCache(backend Backend, ttl time.Duration) Cache

type ChainBackend

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

func NewChainBackend

func NewChainBackend(backends ...Backend) *ChainBackend

func (*ChainBackend) Del

func (b *ChainBackend) Del(ctx context.Context, key string) (err error)

func (*ChainBackend) DelAll

func (b *ChainBackend) DelAll(ctx context.Context) (err error)

func (*ChainBackend) Get

func (b *ChainBackend) Get(ctx context.Context, key string) ([]byte, error)

func (*ChainBackend) Set

func (b *ChainBackend) Set(ctx context.Context, key string, value []byte, ttl time.Duration) (err error)

type FreeBackend

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

func NewFreeBackend

func NewFreeBackend(size int) *FreeBackend

func (*FreeBackend) Del

func (b *FreeBackend) Del(_ context.Context, key string) error

func (*FreeBackend) DelAll

func (b *FreeBackend) DelAll(context.Context) error

func (*FreeBackend) Get

func (b *FreeBackend) Get(_ context.Context, key string) ([]byte, error)

func (*FreeBackend) Set

func (b *FreeBackend) Set(_ context.Context, key string, value []byte, ttl time.Duration) error

type Item

type Item struct {
	Value      []byte
	Expiration int64
}

func (Item) Expired

func (i Item) Expired() bool

type MapBackend

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

func NewMapBackend

func NewMapBackend(cleanupInterval time.Duration) *MapBackend

func NewMapBackendFrom

func NewMapBackendFrom(cleanupInterval time.Duration, items map[string]Item) *MapBackend

func (*MapBackend) Del

func (b *MapBackend) Del(_ context.Context, key string) error

func (*MapBackend) DelAll

func (b *MapBackend) DelAll(context.Context) error

func (*MapBackend) DelExpired

func (b *MapBackend) DelExpired()

func (*MapBackend) Get

func (b *MapBackend) Get(_ context.Context, key string) ([]byte, error)

func (*MapBackend) Items

func (b *MapBackend) Items() map[string]Item

func (*MapBackend) Set

func (b *MapBackend) Set(_ context.Context, key string, value []byte, ttl time.Duration) error

type NopCache added in v0.0.5

type NopCache struct{}

func (*NopCache) DelAll added in v0.0.5

func (*NopCache) DelAll(context.Context) error

func (*NopCache) DelByKey added in v0.0.5

func (*NopCache) DelByKey(context.Context, string) error

func (*NopCache) DelByTag added in v0.0.5

func (*NopCache) DelByTag(context.Context, string) error

func (*NopCache) Get added in v0.0.5

func (*NopCache) Set added in v0.0.5

Directories

Path Synopsis
fx module

Jump to

Keyboard shortcuts

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