cache

package
v0.0.9-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package cache is a memory store for key-value pairs for all loaded symbols available for output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	CacheSize    uint32              // Total allowed cumulative size of values (not code) in cache
	CacheUseSize uint32              // Currently used bytes by all values (not code) in cache
	Cache        []map[string]string // All loaded cache items
	Sizes        map[string]uint16   // Size limits for all loaded symbols.
}

Cache stores loaded content, enforcing size limits and keeping track of size usage.

func NewCache

func NewCache() *Cache

NewCache creates a new ready-to-use cache object

func (*Cache) Add

func (ca *Cache) Add(key string, value string, sizeLimit uint16) error

Add adds a cache value under a cache symbol key.

Also stores the size limitation of for key for later updates.

Fails if: - key already defined - value is longer than size limit - adding value exceeds cumulative cache capacity

func (*Cache) Check

func (ca *Cache) Check(key string) bool

Check returns true if a key already exists in the cache.

func (*Cache) Get

func (ca *Cache) Get(key string) (string, error)

Get the content currently loaded for a single key, loaded at any level.

Fails if key has not been loaded.

func (*Cache) Pop

func (ca *Cache) Pop() error

Pop frees the cache of the current level and makes the previous level the current level.

Fails if already on top level.

func (*Cache) Push

func (ca *Cache) Push() error

Push adds a new level to the cache.

func (*Cache) ReservedSize

func (ca *Cache) ReservedSize(key string) (uint16, error)

ReservedSize returns the maximum byte size available for the given symbol.

func (*Cache) Reset

func (ca *Cache) Reset()

Reset flushes all state contents below the top level.

func (*Cache) Update

func (ca *Cache) Update(key string, value string) error

Update sets a new value for an existing key.

Uses the size limitation from when the key was added.

Fails if: - key not defined - value is longer than size limit - replacing value exceeds cumulative cache capacity

func (*Cache) WithCacheSize

func (ca *Cache) WithCacheSize(cacheSize uint32) *Cache

WithCacheSize applies a cumulative cache size limitation for all cached items.

type Memory

type Memory interface {
	Add(key string, val string, sizeLimit uint16) error
	Update(key string, val string) error
	ReservedSize(key string) (uint16, error)
	Get(key string) (string, error)
	Push() error
	Pop() error
	Reset()
}

Memory defines the interface for store of a symbol mapped content store.

Jump to

Keyboard shortcuts

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