cache

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Setup

func Setup()

Types

type Cache

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

Cache is a generic in-memory cache with a max size and LRU management

func NewCache

func NewCache(maxSize int) *Cache

func (*Cache) Delete

func (c *Cache) Delete(key string)

func (*Cache) Get

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

func (*Cache) Set

func (c *Cache) Set(key string, data interface{})

type CacheEntry

type CacheEntry struct {
	Data       interface{}
	LastAccess time.Time // For LRU cache management
}

CacheEntry represents a generic cache entry with a timestamp

type CacheWrapperT

type CacheWrapperT struct {
	Cache *Cache
}

CacheWrapper provides an easy interface for caching with SQLC queries

var CacheWrapper *CacheWrapperT

func NewCacheWrapper

func NewCacheWrapper(maxSize int) *CacheWrapperT

NewCacheWrapper creates a new CacheWrapper with a specified cache size

func (*CacheWrapperT) DeferredWrite

func (cw *CacheWrapperT) DeferredWrite(key string, data interface{}, dbWriteFunc func(context.Context, interface{}) error)

DeferredWrite stores data in cache and writes to the database asynchronously

func (*CacheWrapperT) GetWithCache

func (cw *CacheWrapperT) GetWithCache(ctx context.Context, key string, dbFunc func(context.Context) (interface{}, error)) (interface{}, error)

GetWithCache tries to retrieve the data from cache or falls back to DB function

Jump to

Keyboard shortcuts

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