cache

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

Cache implements the ICache interface

func NewCache

func NewCache[T any](rc *redis.Client, key string, useHash ...bool) *Cache[T]

NewCache creates a new Cache instance

func NewCacheWithMetrics added in v0.1.4

func NewCacheWithMetrics[T any](rc *redis.Client, key string, collector metrics.CacheMetricsCollector, useHash ...bool) *Cache[T]

NewCacheWithMetrics creates a new Cache instance collector

func (*Cache[T]) Delete

func (c *Cache[T]) Delete(ctx context.Context, field string) error

Delete removes data from cache

func (*Cache[T]) Exists added in v0.1.4

func (c *Cache[T]) Exists(ctx context.Context, field string) (bool, error)

Exists checks if cache key exists

func (*Cache[T]) Expire added in v0.1.4

func (c *Cache[T]) Expire(ctx context.Context, field string, expiration time.Duration) error

Expire sets expiration for a cache key

func (*Cache[T]) Get

func (c *Cache[T]) Get(ctx context.Context, field string) (*T, error)

Get retrieves a single item from cache

func (*Cache[T]) GetArray

func (c *Cache[T]) GetArray(ctx context.Context, field string, dest any) error

GetArray retrieves an array of items from cache

func (*Cache[T]) GetMultiple added in v0.1.4

func (c *Cache[T]) GetMultiple(ctx context.Context, fields []string) (map[string]*T, error)

GetMultiple retrieves multiple items from cache

func (*Cache[T]) Key

func (c *Cache[T]) Key(field string) string

Key defines the cache key

func (*Cache[T]) Set

func (c *Cache[T]) Set(ctx context.Context, field string, data *T, expire ...time.Duration) error

Set saves a single item into cache

func (*Cache[T]) SetArray

func (c *Cache[T]) SetArray(ctx context.Context, field string, data any, expire ...time.Duration) error

SetArray saves an array of items into cache

func (*Cache[T]) SetMultiple added in v0.1.4

func (c *Cache[T]) SetMultiple(ctx context.Context, items map[string]*T, expire ...time.Duration) error

SetMultiple saves multiple items into cache

func (*Cache[T]) TTL added in v0.1.4

func (c *Cache[T]) TTL(ctx context.Context, field string) (time.Duration, error)

TTL gets the time to live for a cache key

type ICache

type ICache[T any] interface {
	Get(context.Context, string) (*T, error)
	Set(context.Context, string, *T, ...time.Duration) error
	Delete(context.Context, string) error
	GetArray(context.Context, string, any) error
	SetArray(context.Context, string, any, ...time.Duration) error
	GetMultiple(context.Context, []string) (map[string]*T, error)
	SetMultiple(context.Context, map[string]*T, ...time.Duration) error
	Exists(context.Context, string) (bool, error)
	TTL(context.Context, string) (time.Duration, error)
	Expire(context.Context, string, time.Duration) error
}

ICache defines a general caching interface

Jump to

Keyboard shortcuts

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