cache

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Checksum() string
	Class() string
	Delete(ctx context.Context, key string) error
	Get(ctx context.Context, key string) (value string, exists bool, isCurrent bool, err error)
	// GetAndDelete atomically reads and removes the entry for key,
	// returning whether it existed. The primitive is needed to close
	// the concurrent-redeem race in auth-code / refresh-token rotation
	// (kdex-tech/host-manager#71): two concurrent callers that race on
	// the same key must observe exactly one winner (found=true) and
	// N-1 losers (found=false). Implementations that don't natively
	// expose an atomic GETDEL must guard with their own lock.
	GetAndDelete(ctx context.Context, key string) (value string, exists bool, isCurrent bool, err error)
	// DecrementIfPositive atomically decrements the integer value at key when
	// it exists and is > 0, returning the remaining count and ok=true. When the
	// key is missing or already <= 0 it returns (-1, false, nil) WITHOUT
	// writing — the fail-closed primitive behind bounded-use capability tokens.
	DecrementIfPositive(ctx context.Context, key string) (remaining int64, ok bool, err error)
	Host() string
	Set(ctx context.Context, key string, value string, opts ...SetOption) error
	TTL() time.Duration
	Uncycled() bool
}

type CacheManager

type CacheManager interface {
	Cycle(checksum string, force bool) error
	GetCache(class string, opts CacheOptions) Cache
}

func NewCacheManager

func NewCacheManager(addr, host string, ttl *time.Duration) (CacheManager, error)

type CacheOptions

type CacheOptions struct {
	MaxItems *int
	TTL      *time.Duration
	Uncycled bool
}

type InMemoryCache

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

func (*InMemoryCache) Checksum added in v0.2.7

func (c *InMemoryCache) Checksum() string

func (*InMemoryCache) Class

func (c *InMemoryCache) Class() string

func (*InMemoryCache) DecrementIfPositive added in v0.4.0

func (c *InMemoryCache) DecrementIfPositive(ctx context.Context, key string) (int64, bool, error)

DecrementIfPositive atomically decrements the integer value at key when it exists (in either the current or previous generation, matching the Get/GetAndDelete fallback semantics) and is > 0. It runs the same segment walk as lookupLocked under a single write lock, but — unlike lookupLocked — must know which segment the entry lives in so the decremented value can be written back in place, preserving the existing expiry and LRU element rather than resetting them (mirrors the invariant Set uses when refreshing an existing entry). Missing key or a non-positive/non-integer value fails closed: (-1, false, nil) WITHOUT writing.

func (*InMemoryCache) Delete

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

func (*InMemoryCache) Get

func (c *InMemoryCache) Get(ctx context.Context, key string) (string, bool, bool, error)

func (*InMemoryCache) GetAndDelete added in v0.2.92

func (c *InMemoryCache) GetAndDelete(ctx context.Context, key string) (string, bool, bool, error)

GetAndDelete atomically reads and removes the entry. Implementation: run the same Get walk and, on a hit, evict the entry before releasing the lock. The single c.mu.Lock around both halves is what makes this the contract-required single-winner primitive. See kdex-tech/host-manager#71.

func (*InMemoryCache) Host

func (c *InMemoryCache) Host() string

func (*InMemoryCache) Set

func (c *InMemoryCache) Set(ctx context.Context, key string, value string, opts ...SetOption) error

Set stores a rendered page in the cache.

func (*InMemoryCache) TTL

func (c *InMemoryCache) TTL() time.Duration

func (*InMemoryCache) Uncycled

func (c *InMemoryCache) Uncycled() bool

type InMemoryCacheManager

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

func (*InMemoryCacheManager) Cycle

func (m *InMemoryCacheManager) Cycle(checksum string, force bool) error

func (*InMemoryCacheManager) GetCache

func (m *InMemoryCacheManager) GetCache(class string, opts CacheOptions) Cache

type SetOption added in v0.2.30

type SetOption func(*SetOptions)

func WithTTL added in v0.2.30

func WithTTL(ttl time.Duration) SetOption

type SetOptions added in v0.2.30

type SetOptions struct {
	TTL *time.Duration
}

type ValkeyCache

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

func (*ValkeyCache) Checksum added in v0.2.7

func (s *ValkeyCache) Checksum() string

func (*ValkeyCache) Class

func (s *ValkeyCache) Class() string

func (*ValkeyCache) DecrementIfPositive added in v0.4.0

func (s *ValkeyCache) DecrementIfPositive(ctx context.Context, key string) (int64, bool, error)

DecrementIfPositive atomically decrements the integer value at key when it exists and is > 0, returning the remaining count and ok=true; otherwise it fails closed with (-1, false, nil) WITHOUT writing. This is the bounded-use capability token primitive; callers create these caches with CacheOptions{Uncycled: true}, so — unlike Get/Set — there is no prevPrefix fallback to consider.

func (*ValkeyCache) Delete

func (s *ValkeyCache) Delete(ctx context.Context, key string) error

func (*ValkeyCache) Get

func (s *ValkeyCache) Get(ctx context.Context, key string) (string, bool, bool, error)

func (*ValkeyCache) GetAndDelete added in v0.2.92

func (s *ValkeyCache) GetAndDelete(ctx context.Context, key string) (string, bool, bool, error)

GetAndDelete atomically reads and removes the entry. Backed by Valkey's GETDEL primitive (single round-trip, server-side atomic), so two concurrent callers racing on the same key always produce exactly one winner. See kdex-tech/host-manager#71.

func (*ValkeyCache) Host

func (s *ValkeyCache) Host() string

func (*ValkeyCache) Set

func (s *ValkeyCache) Set(ctx context.Context, key string, value string, opts ...SetOption) error

func (*ValkeyCache) TTL

func (s *ValkeyCache) TTL() time.Duration

func (*ValkeyCache) Uncycled

func (s *ValkeyCache) Uncycled() bool

type ValkeyCacheManager

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

func (*ValkeyCacheManager) Cycle

func (m *ValkeyCacheManager) Cycle(checksum string, force bool) error

func (*ValkeyCacheManager) GetCache

func (m *ValkeyCacheManager) GetCache(class string, opts CacheOptions) Cache

Jump to

Keyboard shortcuts

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