cache

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 31, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package cache provides caching mechanisms for API responses to improve performance and reduce external API calls.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item struct {
	Value      interface{}
	Expiration int64
}

Item represents a cached item with expiration

func (Item) Expired

func (item Item) Expired() bool

Expired checks if the item has expired

type TTLCache

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

TTLCache is a thread-safe cache with time-based expiration

func GetGlobalCache

func GetGlobalCache() *TTLCache

GetGlobalCache returns the global cache instance

func NewTTLCache

func NewTTLCache(defaultTTL, cleanupInterval time.Duration, maxItems int) *TTLCache

NewTTLCache creates a new cache with the specified TTL and cleanup interval maxItems specifies the maximum number of items before oldest are evicted

func (*TTLCache) Clear

func (c *TTLCache) Clear()

Clear removes all items from the cache

func (*TTLCache) Count

func (c *TTLCache) Count() int

Count returns the number of items in the cache

func (*TTLCache) Delete

func (c *TTLCache) Delete(key string)

Delete removes an item from the cache

func (*TTLCache) Get

func (c *TTLCache) Get(key string) (interface{}, bool)

Get retrieves an item from the cache Returns the item and a bool indicating if the item was found

func (*TTLCache) Set

func (c *TTLCache) Set(key string, value interface{})

Set adds an item to the cache with the default TTL

func (*TTLCache) SetWithTTL

func (c *TTLCache) SetWithTTL(key string, value interface{}, ttl time.Duration)

SetWithTTL adds an item to the cache with a specific TTL

func (*TTLCache) Stop

func (c *TTLCache) Stop()

Stop stops the cleanup timer

Jump to

Keyboard shortcuts

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