cache

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterFactory added in v1.1.5

func RegisterFactory(driver string, factory Factory)

Types

type Cache

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

func NewCache

func NewCache(prefix string, store Store) *Cache

Create a new cache

func (*Cache) Get

func (cache *Cache) Get(ctx context.Context, key string, value any) error

func (*Cache) Set

func (cache *Cache) Set(ctx context.Context, key string, value any, ttl time.Duration) error

type Factory added in v1.1.5

type Factory func(opts typed.Typed) (Store, error)

func NewRedisFactory added in v1.1.5

func NewRedisFactory(client *redis.Client) Factory

type MemoryStore

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

func NewMemoryStore

func NewMemoryStore() *MemoryStore

func (*MemoryStore) Get

func (s *MemoryStore) Get(ctx context.Context, key string, value any) error

func (*MemoryStore) Has

func (s *MemoryStore) Has(ctx context.Context, key string) bool

func (*MemoryStore) Set

func (s *MemoryStore) Set(ctx context.Context, key string, value any, ttl time.Duration) error

type RedisStore

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

func NewRedisStore

func NewRedisStore(options *cache.Options) *RedisStore

func (*RedisStore) Get

func (s *RedisStore) Get(ctx context.Context, key string, value interface{}) error

func (*RedisStore) Has

func (s *RedisStore) Has(ctx context.Context, key string) bool

func (*RedisStore) Set

func (s *RedisStore) Set(ctx context.Context, key string, value any, ttl time.Duration) error

type Store

type Store interface {
	// Set an item in the store.
	Set(ctx context.Context, key string, value any, TTL time.Duration) error

	// Get an item from the store.
	// returns an error if key is not found or there is other problems.
	Get(ctx context.Context, key string, value any) error

	// Check if a key exist in the store.
	Has(ctx context.Context, key string) bool
}

Interface to a cache storage.

func Make added in v1.1.5

func Make(driver string, opts typed.Typed) (Store, error)

Jump to

Keyboard shortcuts

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