gocache

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingKey = errors.New("key not found")
)

Functions

This section is empty.

Types

type Cache

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

func NewCache

func NewCache(store Store) *Cache

func (*Cache) Forget

func (c *Cache) Forget(ctx context.Context, key string) error

func (*Cache) GetString

func (c *Cache) GetString(ctx context.Context, key string) (string, error)

func (*Cache) GetStruct

func (c *Cache) GetStruct(ctx context.Context, key string, data any) error

func (*Cache) PutString

func (c *Cache) PutString(ctx context.Context, key string, data string, ttl time.Duration) error

func (*Cache) PutStruct

func (c *Cache) PutStruct(ctx context.Context, key string, data any, ttl time.Duration) error

func (*Cache) RememberString

func (c *Cache) RememberString(ctx context.Context, key string, ttl time.Duration, f CacheStringFunc) (string, error)

func (*Cache) RememberStruct

func (c *Cache) RememberStruct(ctx context.Context, key string, data any, ttl time.Duration, f CacheStructFunc) error

type CacheStringFunc

type CacheStringFunc func() (string, error)

type CacheStructFunc

type CacheStructFunc func() (any, error)

type MemoryStore

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

func NewMemoryStore

func NewMemoryStore() *MemoryStore

func (*MemoryStore) Forget

func (m *MemoryStore) Forget(ctx context.Context, key string) error

func (*MemoryStore) GetString

func (m *MemoryStore) GetString(ctx context.Context, key string) (string, error)

func (*MemoryStore) GetStruct

func (m *MemoryStore) GetStruct(ctx context.Context, key string, data any) error

func (*MemoryStore) PutString

func (m *MemoryStore) PutString(ctx context.Context, key string, data string, ttl time.Duration) error

func (*MemoryStore) PutStruct

func (m *MemoryStore) PutStruct(ctx context.Context, key string, data any, ttl time.Duration) error

type RedisStore

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

func NewRedisStore

func NewRedisStore(client *redis.Client) *RedisStore

func (*RedisStore) Forget

func (r *RedisStore) Forget(ctx context.Context, key string) error

func (*RedisStore) GetString

func (r *RedisStore) GetString(ctx context.Context, key string) (string, error)

func (*RedisStore) GetStruct

func (r *RedisStore) GetStruct(ctx context.Context, key string, data any) error

func (*RedisStore) PutString

func (r *RedisStore) PutString(ctx context.Context, key string, data string, ttl time.Duration) error

func (*RedisStore) PutStruct

func (r *RedisStore) PutStruct(ctx context.Context, key string, data any, ttl time.Duration) error

type RueidisStore added in v1.1.0

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

func NewRueidisStore added in v1.1.0

func NewRueidisStore(c rueidis.Client) *RueidisStore

func (*RueidisStore) Forget added in v1.1.0

func (r *RueidisStore) Forget(ctx context.Context, key string) error

func (*RueidisStore) GetString added in v1.1.0

func (r *RueidisStore) GetString(ctx context.Context, key string) (string, error)

func (*RueidisStore) GetStruct added in v1.1.0

func (r *RueidisStore) GetStruct(ctx context.Context, key string, data any) error

func (*RueidisStore) PutString added in v1.1.0

func (r *RueidisStore) PutString(ctx context.Context, key string, data string, ttl time.Duration) error

func (*RueidisStore) PutStruct added in v1.1.0

func (r *RueidisStore) PutStruct(ctx context.Context, key string, data any, ttl time.Duration) error

type Store

type Store interface {
	GetString(ctx context.Context, key string) (string, error)
	PutString(ctx context.Context, key string, data string, ttl time.Duration) error

	GetStruct(ctx context.Context, key string, data any) error
	PutStruct(ctx context.Context, key string, data any, ttl time.Duration) error

	Forget(ctx context.Context, key string) error
}

Jump to

Keyboard shortcuts

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