dynacache

package
v0.123.12 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanKey

func CleanKey(s string) string

CleanKey turns s into a format suitable for a cache key for this package. The key will be a Unix-styled path with a leading slash but no trailing slash.

Types

type Cache

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

A dynamic partitioned cache.

func New

func New(opts Options) *Cache

New creates a new cache.

func (*Cache) ClearMatching

func (c *Cache) ClearMatching(predicate func(k, v any) bool)

ClearMatching clears all partition for which the predicate returns true.

func (*Cache) ClearOnRebuild

func (c *Cache) ClearOnRebuild(changeset ...identity.Identity)

ClearOnRebuild prepares the cache for a new rebuild taking the given changeset into account.

func (*Cache) DrainEvictedIdentities

func (c *Cache) DrainEvictedIdentities() []identity.Identity

DrainEvictedIdentities drains the evicted identities from the cache.

func (*Cache) Keys

func (c *Cache) Keys(predicate func(s string) bool) []string

Keys returns a list of keys in all partitions.

func (*Cache) Stop

func (c *Cache) Stop()

Stop stops the cache.

type ClearWhen

type ClearWhen int
const (
	ClearOnRebuild ClearWhen = iota + 1
	ClearOnChange
	ClearNever
)

type Options

type Options struct {
	Log           loggers.Logger
	CheckInterval time.Duration
	MaxSize       int
	MinMaxSize    int
	Running       bool
}

Options for the cache.

type OptionsPartition

type OptionsPartition struct {
	// When to clear the this partition.
	ClearWhen ClearWhen

	// Weight is a number between 1 and 100 that indicates how, in general, how big this partition may get.
	Weight int
}

Options for a partition.

func (OptionsPartition) CalculateMaxSize

func (o OptionsPartition) CalculateMaxSize(maxSizePerPartition int) int

func (OptionsPartition) WeightFraction

func (o OptionsPartition) WeightFraction() float64

type Partition

type Partition[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Partition is a partition in the cache.

func GetOrCreatePartition

func GetOrCreatePartition[K comparable, V any](c *Cache, name string, opts OptionsPartition) *Partition[K, V]

GetOrCreatePartition gets or creates a partition with the given name.

func (*Partition[K, V]) Clear

func (p *Partition[K, V]) Clear()

func (*Partition[K, V]) Get

func (p *Partition[K, V]) Get(ctx context.Context, key K) (V, bool)

func (*Partition[K, V]) GetOrCreate

func (p *Partition[K, V]) GetOrCreate(key K, create func(key K) (V, error)) (V, error)

GetOrCreate gets or creates a value for the given key.

func (*Partition[K, V]) GetOrCreateWitTimeout

func (p *Partition[K, V]) GetOrCreateWitTimeout(key K, duration time.Duration, create func(key K) (V, error)) (V, error)

GetOrCreateWitTimeout gets or creates a value for the given key and times out if the create function takes too long.

func (*Partition[K, V]) Keys

func (p *Partition[K, V]) Keys() []K

type PartitionManager

type PartitionManager interface {
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

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