cache

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package cache provides a thread-safe TTL + LRU cache used to retain recently completed scan results. Values are bounded both by entry count (LRU eviction, configured via cache.max_entries) and by age (time expiry, configured via cache.ttl). No persistent storage — a restart loses the cache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewID

func NewID(host string, t time.Time) string

NewID returns a 32-hex-character ID derived from host, the scan timestamp, and a 12-byte cryptographic nonce. The nonce dominates the entropy so two scans of the same host at the same instant still receive distinct IDs — the host/timestamp inputs only provide debuggability if a future version chooses to make IDs deterministic.

Types

type Cache

type Cache[V any] struct {
	// contains filtered or unexported fields
}

Cache is a thread-safe TTL + LRU cache keyed by string. Constructed via New.

func New

func New[V any](maxEntries int, ttl time.Duration) *Cache[V]

New builds a Cache. A non-positive maxEntries falls back to 1000 to avoid the underlying lib's "always full" behaviour at size 0. A zero ttl disables time-based expiry (LRU only).

func (*Cache[V]) Get

func (c *Cache[V]) Get(key string) (V, bool)

Get returns the value under key and a presence boolean. A returned false means either the key was never stored or its TTL has elapsed.

func (*Cache[V]) Len

func (c *Cache[V]) Len() int

Len returns the number of currently-stored entries.

func (*Cache[V]) Purge

func (c *Cache[V]) Purge()

Purge removes all entries.

func (*Cache[V]) Put

func (c *Cache[V]) Put(key string, value V)

Put stores value under key.

Jump to

Keyboard shortcuts

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