cache

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package cache provides a simple in-memory cache with TTL support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Get retrieves a value from the cache. Returns nil if not found or expired.
	Get(key string) (any, bool)
	// Set stores a value in the cache with the specified TTL.
	Set(key string, value any, ttl time.Duration)
	// Delete removes a value from the cache.
	Delete(key string)
	// Clear removes all values from the cache.
	Clear()
	// Stats returns cache statistics.
	Stats() CacheStats
}

Cache provides thread-safe caching with expiration support.

func NewMemoryCache

func NewMemoryCache(cleanupInterval time.Duration) Cache

NewMemoryCache creates a new in-memory cache with automatic cleanup. The cleanupInterval determines how often expired entries are removed.

func NewNoOpCache

func NewNoOpCache() Cache

NewNoOpCache creates a cache that doesn't cache anything.

type CacheStats

type CacheStats struct {
	Hits        int64 // Number of successful Get operations
	Misses      int64 // Number of failed Get operations (not found or expired)
	Sets        int64 // Number of Set operations
	Evictions   int64 // Number of expired entries cleaned up
	CurrentSize int   // Current number of cached entries
}

CacheStats holds cache performance metrics.

Jump to

Keyboard shortcuts

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