Help us shape the future of Go! Take the 2026 Go Developer Survey

cache

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

README

cache

import "github.com/agentstation/starmap/internal/server/cache"

Package cache provides an in-memory caching layer for the HTTP server. It uses patrickmn/go-cache for TTL-based caching with LRU-like eviction.

Index

type Cache

Cache wraps go-cache with additional features for HTTP caching.

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

func New
func New(defaultTTL, cleanupInterval time.Duration) *Cache

New creates a cache with the given default TTL and cleanup interval. The TTL sets entry expiration. The cleanup interval controls expired-entry removal.

func (*Cache) ActivateGeneration
func (c *Cache) ActivateGeneration(sequence uint64, generationID string)

ActivateGeneration atomically changes the visible namespace and removes old entries. Repeating the same generation is a no-op.

func (*Cache) Clear
func (c *Cache) Clear()

Clear removes all items from the cache.

func (*Cache) Delete
func (c *Cache) Delete(key string)

Delete removes a value from the cache.

func (*Cache) GenerationID
func (c *Cache) GenerationID() string

GenerationID returns the active cache namespace.

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

Get retrieves a value from the cache.

func (*Cache) GetGeneration
func (c *Cache) GetGeneration(sequence uint64, generationID, key string) (any, bool)

GetGeneration retrieves a key only from generationID. The first request may initialize an empty cache, but an in-flight old request cannot reactivate a superseded namespace.

func (*Cache) GetStats
func (c *Cache) GetStats() Stats

GetStats returns current cache statistics.

func (*Cache) ItemCount
func (c *Cache) ItemCount() int

ItemCount returns the number of items in the cache.

func (*Cache) Set
func (c *Cache) Set(key string, value any)

Set stores a value in the cache with default TTL.

func (*Cache) SetGeneration
func (c *Cache) SetGeneration(sequence uint64, generationID, key string, value any)

SetGeneration stores a key in the active generation namespace.

func (*Cache) SetWithTTL
func (c *Cache) SetWithTTL(key string, value any, ttl time.Duration)

SetWithTTL stores a value in the cache with custom TTL.

type Stats

Stats returns cache statistics.

type Stats struct {
    ItemCount    int    `json:"item_count"`
    GenerationID string `json:"generation_id,omitempty"`
    Sequence     uint64 `json:"sequence"`
}

Generated by gomarkdoc

Documentation

Overview

Package cache provides an in-memory caching layer for the HTTP server. It uses patrickmn/go-cache for TTL-based caching with LRU-like eviction.

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 wraps go-cache with additional features for HTTP caching.

func New

func New(defaultTTL, cleanupInterval time.Duration) *Cache

New creates a cache with the given default TTL and cleanup interval. The TTL sets entry expiration. The cleanup interval controls expired-entry removal.

func (*Cache) ActivateGeneration added in v0.1.0

func (c *Cache) ActivateGeneration(sequence uint64, generationID string)

ActivateGeneration atomically changes the visible namespace and removes old entries. Repeating the same generation is a no-op.

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all items from the cache.

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete removes a value from the cache.

func (*Cache) GenerationID added in v0.1.0

func (c *Cache) GenerationID() string

GenerationID returns the active cache namespace.

func (*Cache) Get

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

Get retrieves a value from the cache.

func (*Cache) GetGeneration added in v0.1.0

func (c *Cache) GetGeneration(sequence uint64, generationID, key string) (any, bool)

GetGeneration retrieves a key only from generationID. The first request may initialize an empty cache, but an in-flight old request cannot reactivate a superseded namespace.

func (*Cache) GetStats

func (c *Cache) GetStats() Stats

GetStats returns current cache statistics.

func (*Cache) ItemCount

func (c *Cache) ItemCount() int

ItemCount returns the number of items in the cache.

func (*Cache) Set

func (c *Cache) Set(key string, value any)

Set stores a value in the cache with default TTL.

func (*Cache) SetGeneration added in v0.1.0

func (c *Cache) SetGeneration(sequence uint64, generationID, key string, value any)

SetGeneration stores a key in the active generation namespace.

func (*Cache) SetWithTTL

func (c *Cache) SetWithTTL(key string, value any, ttl time.Duration)

SetWithTTL stores a value in the cache with custom TTL.

type Stats

type Stats struct {
	ItemCount    int    `json:"item_count"`
	GenerationID string `json:"generation_id,omitempty"`
	Sequence     uint64 `json:"sequence"`
}

Stats returns cache statistics.

Jump to

Keyboard shortcuts

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