Documentation ¶
Overview ¶
Package multi implements a multi-level caching system with local and remote caches.
Index ¶
- type BloomFilter
- func (bf *BloomFilter) Add(key string)
- func (bf *BloomFilter) Load(ctx context.Context) error
- func (bf *BloomFilter) PeriodicRebuild(ctx context.Context)
- func (bf *BloomFilter) Rebuild(ctx context.Context) error
- func (bf *BloomFilter) Save(ctx context.Context)
- func (bf *BloomFilter) Test(key string) bool
- type Cache
- func (c *Cache) Clear(ctx context.Context) error
- func (c *Cache) Close() error
- func (c *Cache) Delete(ctx context.Context, key string) error
- func (c *Cache) Get(ctx context.Context, key string, value any) (bool, error)
- func (c *Cache) GetMulti(ctx context.Context, keys []string) (map[string]any, error)
- func (c *Cache) Set(ctx context.Context, key string, value any, ttl ...time.Duration) error
- func (c *Cache) SetMulti(ctx context.Context, items map[string]any, ttl ...time.Duration) error
- type CacheOperations
- type Prefetcher
- type Resilience
- func (r *Resilience) Clear(ctx context.Context) error
- func (r *Resilience) Delete(ctx context.Context, key string) error
- func (r *Resilience) Get(ctx context.Context, key string, entry *models.Entry) error
- func (r *Resilience) GetMulti(ctx context.Context, keys []string) (map[string]*models.Entry, error)
- func (r *Resilience) Set(ctx context.Context, key string, entry *models.Entry, ttl time.Duration) error
- func (r *Resilience) SetMulti(ctx context.Context, entries map[string]*models.Entry, ttl time.Duration) error
- type TTLManager
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) Close ¶
Close closes all local and remote caches associated with the Cache instance, returning an error if any occur.
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.
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) GetMulti ¶
GetMulti retrieves multiple entries from 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.