multi

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: 23 Imported by: 0

Documentation

Overview

Package multi implements a multi-level caching system with local and remote caches.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BloomFilter

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

BloomFilter defines the bloom filter structure.

func NewBloomFilter

func NewBloomFilter(mlc *Cache) *BloomFilter

NewBloomFilter creates a new BloomFilter instance.

func (*BloomFilter) Add

func (bf *BloomFilter) Add(key string)

Add adds a key to the bloom filter.

func (*BloomFilter) Load

func (bf *BloomFilter) Load(ctx context.Context) error

Load retrieves the bloom filter from the remote cache.

func (*BloomFilter) PeriodicRebuild

func (bf *BloomFilter) PeriodicRebuild(ctx context.Context)

PeriodicRebuild periodically rebuilds the bloom filter.

func (*BloomFilter) Rebuild

func (bf *BloomFilter) Rebuild(ctx context.Context) error

Rebuild reconstructs the bloom filter from all keys in the remote cache.

func (*BloomFilter) Save

func (bf *BloomFilter) Save(ctx context.Context)

Save persists the bloom filter to the remote cache.

func (*BloomFilter) Test

func (bf *BloomFilter) Test(key string) bool

Test checks if a key might be in the bloom filter.

type Cache

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

Cache represents a multi-layer cache system with local and remote caches.

func (*Cache) Clear

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

Clear clears all cache entries.

func (*Cache) Close

func (c *Cache) Close() error

Close closes all local and remote caches associated with the Cache instance, returning an error if any occur.

func (*Cache) Delete

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

Delete removes a key from the cache.

func (*Cache) Get

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

Get retrieves a value from the cache.

func (*Cache) GetMulti

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

GetMulti retrieves multiple keys from the cache.

func (*Cache) Set

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

Set sets a value in the cache.

func (*Cache) SetMulti

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

SetMulti sets multiple keys in the cache.

type CacheOperations

type CacheOperations interface {
	Get(ctx context.Context, key string, value any) (bool, error)
	Set(ctx context.Context, key string, value any, ttl ...time.Duration) error
	Delete(ctx context.Context, key string) error
	Clear(ctx context.Context) error
	GetMulti(ctx context.Context, keys []string) (map[string]any, error)
	SetMulti(ctx context.Context, items map[string]any, ttl ...time.Duration) error
	Close() error
}

CacheOperations defines the interface for cache operations.

func NewCache

func NewCache(ctx context.Context, cfg *config.Config, client redis.Cmdable) (CacheOperations, error)

NewCache creates a new Cache instance.

type Prefetcher

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

Prefetcher implements the prefetching mechanism.

func NewPrefetcher

func NewPrefetcher(cache *Cache) *Prefetcher

NewPrefetcher creates a new Prefetcher instance.

func (*Prefetcher) Run

func (p *Prefetcher) Run(ctx context.Context)

Run starts the prefetcher routine.

func (*Prefetcher) Warmup

func (p *Prefetcher) Warmup(ctx context.Context)

Warmup preloads specified keys into the cache.

type Resilience

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

Resilience manages circuit breakers and retry mechanisms.

func NewResilience

func NewResilience(cache *Cache) *Resilience

NewResilience creates a new Resilience instance.

func (*Resilience) Clear

func (r *Resilience) Clear(ctx context.Context) error

Clear removes all keys from the remote cache with resilience.

func (*Resilience) Delete

func (r *Resilience) Delete(ctx context.Context, key string) error

Delete removes a key from the remote cache with resilience.

func (*Resilience) Get

func (r *Resilience) Get(ctx context.Context, key string, entry *models.Entry) error

Get retrieves a value from the remote cache with resilience.

func (*Resilience) GetMulti

func (r *Resilience) GetMulti(ctx context.Context, keys []string) (map[string]*models.Entry, error)

GetMulti retrieves multiple entries from the remote cache with resilience.

func (*Resilience) Set

func (r *Resilience) Set(ctx context.Context, key string, entry *models.Entry, ttl time.Duration) error

Set sets a value in the remote cache with resilience.

func (*Resilience) SetMulti

func (r *Resilience) SetMulti(ctx context.Context, entries map[string]*models.Entry, ttl time.Duration) error

SetMulti sets multiple entries in the remote cache with resilience.

type TTLManager

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

TTLManager manages adaptive TTL.

func NewTTLManager

func NewTTLManager(cache *Cache) *TTLManager

NewTTLManager creates a new TTLManager instance.

func (*TTLManager) GetTTL

func (tm *TTLManager) GetTTL(key string) time.Duration

GetTTL returns the TTL for a specific key.

func (*TTLManager) Run

func (tm *TTLManager) Run(ctx context.Context)

Run starts the TTL adjustment routine.

Jump to

Keyboard shortcuts

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