cached

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package cached adds a read-through cache to a store.

Index

Constants

View Source
const DefaultTTL = time.Hour

DefaultTTL is the default lifetime for cached entries.

Variables

This section is empty.

Functions

func New

func New(primary, cache trend.Store) trend.Store

New wraps primary with cache.

Types

type Config added in v0.3.0

type Config struct {
	Enabled bool          // Whether reads use the cache.
	TTL     time.Duration // How long entries remain cached.
	Size    int           // Maximum cache size in megabytes; zero is unlimited.
}

Config controls a local read-through cache.

func NewConfig added in v0.3.0

func NewConfig(opts ...Option) Config

NewConfig creates a cache configuration.

func ParseConfig added in v0.3.0

func ParseConfig(q url.Values) (Config, error)

ParseConfig reads cache, cache_ttl, and cache_size query parameters.

type Option added in v0.3.0

type Option func(*Config)

Option configures a cache.

func WithCache added in v0.3.0

func WithCache(enabled bool) Option

WithCache enables or disables caching.

func WithCacheSize added in v0.3.0

func WithCacheSize(size int) Option

WithCacheSize sets the cache size limit in megabytes. Zero means unlimited.

func WithCacheTTL added in v0.3.0

func WithCacheTTL(ttl time.Duration) Option

WithCacheTTL sets the cache entry lifetime.

Jump to

Keyboard shortcuts

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