cache

package
v2.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemCache

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

MemCache is an in-process storage.Cache.

func NewMemCache

func NewMemCache() *MemCache

func NewMemCacheWithOptions added in v2.2.0

func NewMemCacheWithOptions(o MemCacheOptions) *MemCache

NewMemCacheWithOptions builds a cache from an explicit configuration.

func NewMemCacheWithSweep

func NewMemCacheWithSweep(interval time.Duration) *MemCache

NewMemCacheWithSweep sets the sweep interval. Zero or less starts no sweeper, leaving expiry entirely lazy.

func (*MemCache) Close

func (m *MemCache) Close() error

func (*MemCache) Del

func (m *MemCache) Del(ctx context.Context, keys ...string) error

func (*MemCache) Expire

func (m *MemCache) Expire(ctx context.Context, key string, ttl time.Duration) error

func (*MemCache) Get

func (m *MemCache) Get(ctx context.Context, key string) (string, error)

func (*MemCache) Incr

func (m *MemCache) Incr(ctx context.Context, key string, delta int64) (int64, error)

func (*MemCache) Set

func (m *MemCache) Set(ctx context.Context, key, val string, ttl time.Duration) error

func (*MemCache) String

func (c *MemCache) String() string

NewMemCache returns a cache that sweeps expired entries every defaultSweepInterval. Call Close when the instance is not process-wide. String identifies the backend, which is what the deprecated AdapterCache interface reports through storage.LegacyAdapter.

type MemCacheOptions added in v2.2.0

type MemCacheOptions struct {
	// SweepInterval is how often expired entries are collected. Zero or less
	// starts no sweeper, leaving expiry entirely lazy.
	SweepInterval time.Duration

	// MaxEntries caps the number of entries held. Zero means
	// defaultMaxEntries; a negative value means no limit, which is only
	// appropriate when the keyspace is known to be bounded by something else.
	//
	// The cap is enforced per shard, so the effective total is rounded down to
	// a multiple of shardCount.
	MaxEntries int
}

MemCacheOptions configures NewMemCacheWithOptions.

type Memory

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

func NewMemory

func NewMemory() *Memory

NewMemory returns a cache that sweeps expired entries every defaultCleanupInterval.

Lazy deletion on Get is not enough to reclaim memory: a key that is written and never read again stays forever, so a long-running process only grows (issue #31).

Call Close when the instance is not process-wide (repeated construction in tests, for example). Skipping it does not leak without bound — each instance owns exactly one goroutine.

func NewMemoryWithCleanupInterval

func NewMemoryWithCleanupInterval(interval time.Duration) *Memory

NewMemoryWithCleanupInterval sets the sweep interval. A value of zero or less starts no sweeper, falling back to purely lazy expiry.

func (*Memory) Close

func (m *Memory) Close() error

Close stops the sweeper. It is safe to call more than once.

It is deliberately not part of storage.AdapterCache, to avoid breaking existing implementations; holders of the interface can reach it by assertion:

if c, ok := cache.(interface{ Close() error }); ok {
    _ = c.Close()
}

func (*Memory) Decrease

func (m *Memory) Decrease(key string) error

func (*Memory) Del

func (m *Memory) Del(key string) error

func (*Memory) Expire

func (m *Memory) Expire(key string, dur time.Duration) error

Expire replaces the item for the same reason calculate does: the item it reads is already visible to concurrent readers.

func (*Memory) Get

func (m *Memory) Get(key string) (string, error)

func (*Memory) HashDel

func (m *Memory) HashDel(hk, key string) error

func (*Memory) HashGet

func (m *Memory) HashGet(hk, key string) (string, error)

func (*Memory) Increase

func (m *Memory) Increase(key string) error

func (*Memory) Set

func (m *Memory) Set(key string, val interface{}, expire int) error

func (*Memory) String

func (*Memory) String() string

type Message

type Message struct {
	queue.Message
}

func (*Message) GetID

func (m *Message) GetID() string

func (*Message) GetPrefix

func (m *Message) GetPrefix() (prefix string)

func (*Message) GetStream

func (m *Message) GetStream() string

func (*Message) GetValues

func (m *Message) GetValues() map[string]interface{}

func (*Message) SetID

func (m *Message) SetID(id string)

func (*Message) SetPrefix

func (m *Message) SetPrefix(prefix string)

func (*Message) SetStream

func (m *Message) SetStream(stream string)

func (*Message) SetValues

func (m *Message) SetValues(values map[string]interface{})

Jump to

Keyboard shortcuts

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