cache

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package cache provides a TTL caching wrapper around a gpu.Collector.

The wrapper takes a single consistent snapshot of all devices per refresh: the first read after expiry calls the inner DeviceCount() once and then Device(0..n-1) once each, stores the resulting []gpu.Device with a fetch timestamp, and serves every read within the TTL window from that snapshot without touching the inner collector. Errors during a refresh are never cached — they propagate to the caller and leave the cache invalid so the next read retries. Init, Shutdown and Backend pass straight through.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cached

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

Cached wraps a gpu.Collector and serves DeviceCount/Device from a snapshot refreshed at most once per ttl. All snapshot state is mutex-guarded.

func New

func New(inner gpu.Collector, ttl time.Duration) *Cached

New returns a Cached wrapping inner with the given ttl, using time.Now as its clock.

func (*Cached) Backend

func (c *Cached) Backend() string

Backend passes through to the inner collector.

func (*Cached) Device

func (c *Cached) Device(i int) (*gpu.Device, error)

Device returns a copy pointer to the device at index i from the current snapshot, refreshing first if the snapshot is missing or expired. It returns an error if i is out of range.

func (*Cached) DeviceCount

func (c *Cached) DeviceCount() (int, error)

DeviceCount returns the number of devices in the current snapshot, refreshing first if the snapshot is missing or expired.

func (*Cached) Init

func (c *Cached) Init() error

Init passes through to the inner collector.

func (*Cached) Shutdown

func (c *Cached) Shutdown() error

Shutdown passes through to the inner collector.

Jump to

Keyboard shortcuts

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