Documentation
¶
Index ¶
- func NewDriver(storeConfig dgcache.StoreConfig) (cache.Driver, error)
- type Config
- type Driver
- func (d *Driver) Close() error
- func (d *Driver) Decrement(ctx context.Context, key string, value int64) (int64, error)
- func (d *Driver) Flush(ctx context.Context) error
- func (d *Driver) FlushTags(ctx context.Context, tags ...string) error
- func (d *Driver) Forever(ctx context.Context, key string, value interface{}) error
- func (d *Driver) Forget(ctx context.Context, key string) error
- func (d *Driver) ForgetMultiple(ctx context.Context, keys []string) error
- func (d *Driver) Get(ctx context.Context, key string) (interface{}, error)
- func (d *Driver) GetMultiple(ctx context.Context, keys []string) (map[string]interface{}, error)
- func (d *Driver) GetPrefix() string
- func (d *Driver) Has(ctx context.Context, key string) (bool, error)
- func (d *Driver) Increment(ctx context.Context, key string, value int64) (int64, error)
- func (d *Driver) Missing(ctx context.Context, key string) (bool, error)
- func (d *Driver) Name() string
- func (d *Driver) Put(ctx context.Context, key string, value interface{}, ttl time.Duration) error
- func (d *Driver) PutMultiple(ctx context.Context, items map[string]interface{}, ttl time.Duration) error
- func (d *Driver) SetPrefix(prefix string)
- func (d *Driver) Stats() cache.Stats
- func (d *Driver) Tags(tags ...string) cache.TaggedStore
- type Metrics
- func (m *Metrics) RecordDelete(bytes int64)
- func (m *Metrics) RecordEviction(bytes int64)
- func (m *Metrics) RecordHit()
- func (m *Metrics) RecordMiss()
- func (m *Metrics) RecordSet(bytes int64)
- func (m *Metrics) RecordUpdate(oldBytes, newBytes int64)
- func (m *Metrics) Reset()
- func (m *Metrics) Stats() cache.Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// MaxItems is the maximum number of items in the cache.
// 0 means unlimited (default).
MaxItems int
// MaxBytes is the maximum total size of cached items in bytes.
// 0 means unlimited (default).
MaxBytes int64
// EvictionPolicy determines how items are evicted when limits are reached.
// Options: "lru" (default), "lfu", "fifo"
EvictionPolicy string
// CleanupInterval is how often expired items are cleaned up.
// Default: 1 minute
CleanupInterval time.Duration
// EnableMetrics enables collection of cache statistics.
// Default: false
EnableMetrics bool
}
Config represents the configuration for the memory cache driver.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a default memory cache configuration.
func (Config) WithCleanupInterval ¶
WithCleanupInterval sets the cleanup interval.
func (Config) WithEvictionPolicy ¶
WithEvictionPolicy sets the eviction policy.
func (Config) WithMaxBytes ¶
WithMaxBytes sets the maximum total size in bytes.
func (Config) WithMaxItems ¶
WithMaxItems sets the maximum number of items.
func (Config) WithMetrics ¶
WithMetrics enables or disables metrics collection.
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver is an in-memory cache driver.
func (*Driver) ForgetMultiple ¶
ForgetMultiple removes multiple values from the cache.
func (*Driver) GetMultiple ¶
GetMultiple retrieves multiple values from the cache.
func (*Driver) PutMultiple ¶
func (d *Driver) PutMultiple(ctx context.Context, items map[string]interface{}, ttl time.Duration) error
PutMultiple stores multiple values in the cache.
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics tracks cache statistics.
func (*Metrics) RecordDelete ¶
RecordDelete decrements the item count and updates size tracking.
func (*Metrics) RecordEviction ¶
RecordEviction increments the eviction counter and updates size tracking.
func (*Metrics) RecordUpdate ¶
RecordUpdate updates size tracking for an existing item.