cache

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cache provides file-based caching for API responses

Index

Constants

View Source
const (
	// DefaultTTL is the default time-to-live for cache entries
	DefaultTTL = 24 * time.Hour
)

Variables

This section is empty.

Functions

func GenerateKey

func GenerateKey(params ...interface{}) string

GenerateKey creates a unique cache key from parameters

Types

type Cache

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

Cache provides file-based caching functionality

func New

func New(dir string, opts ...Option) (*Cache, error)

New creates a new Cache instance

func (*Cache) CleanExpired

func (c *Cache) CleanExpired() (int, error)

CleanExpired removes all expired entries from the cache

func (*Cache) Clear

func (c *Cache) Clear() error

Clear removes all entries from the cache

func (*Cache) Delete

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

Delete removes a specific entry from the cache

func (*Cache) Exists

func (c *Cache) Exists(key string) bool

Exists checks if a cache entry exists and is not expired

func (*Cache) Get

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

Get retrieves a cached entry if it exists and is not expired

func (*Cache) IsEnabled

func (c *Cache) IsEnabled() bool

IsEnabled returns whether caching is enabled

func (*Cache) Set

func (c *Cache) Set(key string, data []byte) error

Set stores data in the cache

func (*Cache) SetEnabled

func (c *Cache) SetEnabled(enabled bool)

SetEnabled enables or disables the cache

func (*Cache) Stats

func (c *Cache) Stats() (entries int, totalSize int64, err error)

Stats returns cache statistics

type Entry

type Entry struct {
	Data      json.RawMessage `json:"data"`
	CreatedAt time.Time       `json:"created_at"`
	ExpiresAt time.Time       `json:"expires_at"`
	Key       string          `json:"key"`
}

Entry represents a cached item with metadata

type Option

type Option func(*Cache)

Option configures the Cache

func WithEnabled

func WithEnabled(enabled bool) Option

WithEnabled enables or disables the cache

func WithTTL

func WithTTL(ttl time.Duration) Option

WithTTL sets a custom TTL for cache entries

Jump to

Keyboard shortcuts

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