cache

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: Apache-2.0 Imports: 7 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 (*Cache[T]) Delete

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

Delete removes data from cache

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]) 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

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
}

ICache defines a general caching interface

Jump to

Keyboard shortcuts

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