livecache

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 4 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

Overview

Package livecache keeps the newest value per live key ("<meter>/<channel>") and publishes a change event for every new value. Values older than 3 × their device interval are missing (spec 5.1).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is safe for concurrent use by collectors (writers) and readers.

func New

func New(pub Publisher, clock util.Clock) (*Cache, error)

New returns an empty cache.

func (*Cache) Delete

func (c *Cache) Delete(keys ...string)

Delete removes keys (meter removed by a config change).

func (*Cache) Get

func (c *Cache) Get(key string) (Value, bool)

Get returns the value of key unless it is missing (unknown or too old).

func (*Cache) Set

func (c *Cache) Set(key string, v Value, interval time.Duration)

Set stores v for key; interval is the device's poll interval. A change event is published when the value differs from the stored one.

type Publisher

type Publisher interface {
	Publish(e eventbus.Event)
}

Publisher is the part of the event bus the cache needs.

type Value

type Value struct {
	Num    float64
	Text   string
	Unit   string
	Approx bool // estimated, e.g. a SoC averaged without capacities
	At     time.Time
}

Value is one live value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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