cache

package
v0.1.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: AGPL-3.0 Imports: 2 Imported by: 1

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 {
	// Total allowed cumulative size of values (not code) in cache
	CacheSize uint32
	// Currently used bytes by all values (not code) in cache
	CacheUseSize uint32
	// All loaded cache items
	Cache []map[string]string
	// Size limits for all loaded symbols.
	Sizes map[string]uint16
	// Last inserted value (regardless of scope)
	LastValue string
	// contains filtered or unexported fields
}

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

TODO: hide values from client, while allowing cbor serialization

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 implements the Memory interface.

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 implements the Memory interface.

func (*Cache) Invalid

func (ca *Cache) Invalid() bool

Invalid implements the Memory interface.

func (*Cache) Invalidate

func (ca *Cache) Invalidate()

Invalidate implements the Memory interface.

func (*Cache) Keys

func (ca *Cache) Keys(level uint32) []string

Keys implements the Memory interface.

func (*Cache) Last

func (ca *Cache) Last() string

Last implements the Memory interface.

TODO: needs to be invalidated when out of scope

func (*Cache) Levels

func (ca *Cache) Levels() uint32

Levels implements the Memory interface.

func (*Cache) Pop

func (ca *Cache) Pop() error

Pop implements the Memory interface.

func (*Cache) Push

func (ca *Cache) Push() error

Push implements the Memory interface.

func (*Cache) ReservedSize

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

ReservedSize implements the Memory interface.

func (*Cache) Reset

func (ca *Cache) Reset()

Reset implements the Memory interface.

func (*Cache) Update

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

Update implements the Memory interface.

func (*Cache) WithCacheSize

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

WithCacheSize is a chainable method that applies a cumulative cache size limitation for all cached items.

type Memory

type Memory interface {
	// Add adds a cache value under a cache symbol key.
	//
	// Also stores the size limitation of for key for later updates.
	//
	// Must fail if:
	// 	* key already defined
	// 	* value is longer than size limit
	// 	* adding value exceeds cumulative cache capacity
	Add(key string, val string, sizeLimit uint16) error
	// Update sets a new value for an existing key.
	//
	// Uses the size limitation from when the key was added.
	//
	// Must fail if:
	// - key not defined
	// - value is longer than size limit
	// - replacing value exceeds cumulative cache capacity
	Update(key string, val string) error
	// ReservedSize returns the maximum byte size available for the given symbol.
	ReservedSize(key string) (uint16, error)
	// Get the content currently loaded for a single key, loaded at any level.
	//
	// Must fail if key has not been loaded.
	Get(key string) (string, error)
	// Push adds a new level to the cache.
	Push() error
	// Pop frees the cache of the current level and makes the previous level the current level.
	//
	// Fails if already on top level.
	Pop() error
	// Reset flushes all state contents below the top level.
	Reset()
	// Levels returns the current number of levels.
	Levels() uint32
	// Keys returns all storage keys for the given level.
	Keys(level uint32) []string
	// Last returns the last inserted value
	//
	// The stored last inserter value must be reset to an empty string
	Last() string
	// Invalidate marks a cache as invalid.
	//
	// An invalid cache should not be persisted or propagated
	Invalidate()
	// Invalid returns true if cache is invalid.
	//
	// An invalid cache should not be persisted or propagated
	Invalid() bool
}

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

Source Files

  • cache.go
  • doc.go
  • log.go
  • memory.go

Jump to

Keyboard shortcuts

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