limited

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: MIT Imports: 9 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 struct {
	// contains filtered or unexported fields
}

Cache combines cache operations with key tracking.

func New

func New(maxSize uint64, defaultTTL time.Duration, logger *zap.Logger) (*Cache, error)

New creates a new Cache instance.

func (*Cache) Clear

func (c *Cache) Clear(ctx context.Context) error

Clear clears the entire cache and stops tracking all keys.

func (*Cache) Close

func (c *Cache) Close() error

Close closes the Cache.

func (*Cache) Delete

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

Delete removes a cache entry and stops tracking the key.

func (*Cache) Flush

func (c *Cache) Flush(ctx context.Context)

Flush clears the entire cache and stops tracking all keys.

func (*Cache) Get

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

Get retrieves a cache entry.

func (*Cache) GetMulti

func (c *Cache) GetMulti(ctx context.Context, keys []string) (map[string]any, error)

GetMulti retrieves multiple cache entries.

func (*Cache) Keys

func (c *Cache) Keys(ctx context.Context) []string

Keys returns all keys in the cache.

func (*Cache) Set

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

Set sets a cache entry and tracks the key.

func (*Cache) SetMulti

func (c *Cache) SetMulti(ctx context.Context, items map[string]any, ttl ...time.Duration) error

SetMulti sets multiple cache entries and tracks the keys.

type RistrettoStore

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

RistrettoStore implements the Store interface using Ristretto.

func (*RistrettoStore) Close

func (s *RistrettoStore) Close()

Close closes the cache.

func (*RistrettoStore) Delete

func (s *RistrettoStore) Delete(ctx context.Context, key string)

Delete removes a cache entry.

func (*RistrettoStore) Flush

func (s *RistrettoStore) Flush(ctx context.Context)

Flush clears the entire cache.

func (*RistrettoStore) Get

func (s *RistrettoStore) Get(ctx context.Context, key string) (*models.Entry, bool)

Get retrieves a cache entry.

func (*RistrettoStore) GetMulti

func (s *RistrettoStore) GetMulti(ctx context.Context, keys []string) map[string]any

GetMulti retrieves multiple cache entries.

func (*RistrettoStore) Set

func (s *RistrettoStore) Set(ctx context.Context, key string, entry *models.Entry) error

Set sets a cache entry.

func (*RistrettoStore) SetMulti

func (s *RistrettoStore) SetMulti(ctx context.Context, items map[string]any, ttl time.Duration) error

SetMulti sets multiple cache entries.

type Store

type Store interface {
	Set(ctx context.Context, key string, entry *models.Entry) error
	Get(ctx context.Context, key string) (*models.Entry, bool)
	Delete(ctx context.Context, key string)
	Flush(ctx context.Context)
	Close()
	GetMulti(ctx context.Context, keys []string) map[string]any
	SetMulti(ctx context.Context, items map[string]any, ttl time.Duration) error
}

Store defines the interface for cache operations.

func NewRistrettoStore

func NewRistrettoStore(maxSize uint64, defaultTTL time.Duration, logger *zap.Logger) (Store, error)

NewRistrettoStore creates a new RistrettoStore instance.

type Tracker

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

Tracker tracks all keys in the cache.

func NewTracker

func NewTracker(logger *zap.Logger) *Tracker

NewTracker creates a new Tracker instance.

func (*Tracker) Add

func (t *Tracker) Add(ctx context.Context, key string)

Add adds a key to the tracker.

func (*Tracker) Range

func (t *Tracker) Range(ctx context.Context, f func(key string) bool)

Range iterates over all tracked keys.

func (*Tracker) Remove

func (t *Tracker) Remove(ctx context.Context, key string)

Remove removes a key from the tracker.

Jump to

Keyboard shortcuts

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