cache

package
v0.5.12 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 3 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 cache provides an in-memory caching mechanism for application data.

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 provides an in-memory caching mechanism with TTL support.

func New

func New(cacheDuration time.Duration) (*Cache, error)

New creates a new Cache instance. The cleanupInterval determines how often expired items are purged (typically 10 minutes).

func (*Cache) Get

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

Get retrieves data from the cache. Returns (value, true) if found, (nil, false) if not found or expired. Callers should use type assertion on the returned value:

if data, found := cache.Get("key"); found {
    if channels, ok := data.([]Channel); ok {
        // use channels
    }
}

func (*Cache) Set

func (c *Cache) Set(key string, v any) error

Set stores data in the cache with the default expiration time.

Jump to

Keyboard shortcuts

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