Documentation
¶
Index ¶
- Variables
- type Config
- type MemoryStore
- func (s *MemoryStore) Clear(ctx context.Context) error
- func (s *MemoryStore) Close() error
- func (s *MemoryStore) Delete(ctx context.Context, key string) error
- func (s *MemoryStore) Get(ctx context.Context, key string) ([]byte, error)
- func (s *MemoryStore) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
- func (s *MemoryStore) Wait()
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidMaxCost is returned when MaxCost is <= 0. ErrInvalidMaxCost = errors.New("memory: MaxCost must be > 0") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// MaxCost is the maximum cache size in bytes (REQUIRED, must be > 0).
MaxCost int64
// NumCounters is the number of TinyLFU counters (OPTIONAL).
// Default: 10 * MaxCost (recommended for good hit ratio).
NumCounters int64
// BufferItems is the size of the async buffer (OPTIONAL).
// Default: 64
BufferItems int64
// Metrics enables metrics collection (OPTIONAL).
// Default: false
Metrics bool
}
Config holds configuration for MemoryStore.
Reference: .references/ristretto/cache.go (Config struct)
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore is an in-memory cache store backed by Ristretto. Thread-safe for concurrent use.
Reference: .references/ristretto/cache.go (Cache[K,V] with TinyLFU)
func New ¶
func New(cfg Config) (*MemoryStore, error)
New creates a new MemoryStore with the given configuration.
Reference: .references/ristretto/cache.go (NewCache function)
func (*MemoryStore) Clear ¶
func (s *MemoryStore) Clear(ctx context.Context) error
Clear removes all entries from the cache.
Reference: .references/ristretto/cache.go (Clear method)
func (*MemoryStore) Close ¶
func (s *MemoryStore) Close() error
Close releases resources associated with the cache. Idempotent - safe to call multiple times.
Reference: .references/ristretto/cache.go (Close method)
func (*MemoryStore) Delete ¶
func (s *MemoryStore) Delete(ctx context.Context, key string) error
Delete removes a value from the cache. Idempotent - deleting a non-existent key returns nil.
Reference: .references/ristretto/cache.go (Del method)
func (*MemoryStore) Get ¶
Get retrieves a value from the cache by key. Returns cache.ErrNotFound if the key doesn't exist or has expired.
Reference: .references/ristretto/cache.go (Get method)
func (*MemoryStore) Set ¶
Set stores a value in the cache with the specified TTL.
TTL semantics: - ttl == 0: no expiration (lives until evicted) - ttl < 0: no expiration (lives until evicted) - ttl > 0: expires after the specified duration
Reference: .references/ristretto/cache.go (SetWithTTL method)
func (*MemoryStore) Wait ¶
func (s *MemoryStore) Wait()
Wait blocks until all pending Set operations have been processed by Ristretto's internal buffers. Useful in tests to ensure consistency after Set calls.