cachefx

package module
v0.0.0-...-a344ecd Latest Latest
Warning

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

Go to latest
Published: May 9, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

README

cachefx

example:


import (
    "github.com/damonchen/cachefx"
    "go.uber.org/fx"
)

// using memory cache
fx.Module("cache",
    fx.Provide(
        fx.Annotate(
            cachefx.NewMemoryCache,
            fx.As(new(Cache)),
            fx.ResultTags(`name:"cache"`)),
    ))

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound not found
	ErrNotFound = errors.New("key not exists")
)

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Get get value from cache with value
	Get(ctx context.Context, key string) ([]byte, error)
	// Set set value to the cache with key of ttl
	Set(ctx context.Context, key string, value []byte, expiration time.Duration) error
	// Delete clear item in the cache
	Delete(ctx context.Context, key string) error
}

type MemoryCache

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

MemoryCache memory cache

func NewMemoryCache

func NewMemoryCache() *MemoryCache

NewMemoryCache new memory cache

func (*MemoryCache) Delete

func (c *MemoryCache) Delete(ctx context.Context, key string) error

func (*MemoryCache) Get

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

func (*MemoryCache) Set

func (c *MemoryCache) Set(ctx context.Context, key string, value []byte,
	expiration time.Duration) error

type RedisCache

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

RedisCache redis cache

func NewRedisCache

func NewRedisCache(client *redis.Client) *RedisCache

NewRedisCache new redis cache

func (*RedisCache) Delete

func (r *RedisCache) Delete(ctx context.Context, key string) error

func (*RedisCache) Get

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

func (*RedisCache) Set

func (r *RedisCache) Set(ctx context.Context, key string, value []byte,
	expiration time.Duration) error

Jump to

Keyboard shortcuts

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