querycache

package
v0.32.2 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: Unlicense Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxSize is the default maximum cache size in bytes (512 MB)
	DefaultMaxSize = 512 * 1024 * 1024
	// DefaultMaxAge is the default maximum age for cache entries
	DefaultMaxAge = 5 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheStats

type CacheStats struct {
	Entries          int
	CurrentSize      int64 // Compressed size
	MaxSize          int64
	Hits             uint64
	Misses           uint64
	HitRate          float64
	Evictions        uint64
	Invalidations    uint64
	CompressionRatio float64 // Average compression ratio
	CompactionRuns   uint64
}

CacheStats holds cache performance metrics

type EventCache

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

EventCache caches event.S results from database queries with ZSTD compression

func NewEventCache

func NewEventCache(maxSize int64, maxAge time.Duration) *EventCache

NewEventCache creates a new event cache

func (*EventCache) Get

func (c *EventCache) Get(f *filter.F) (serializedJSON [][]byte, found bool)

Get retrieves cached serialized events for a filter (decompresses on the fly)

func (*EventCache) GetEvents added in v0.29.11

func (c *EventCache) GetEvents(f *filter.F) (events []*event.E, found bool)

GetEvents retrieves cached events for a filter (decompresses and deserializes on the fly) This is the new method that returns event.E objects instead of marshaled JSON

func (*EventCache) Invalidate

func (c *EventCache) Invalidate()

Invalidate clears all entries (called when new events are stored)

func (*EventCache) PutEvents added in v0.29.11

func (c *EventCache) PutEvents(f *filter.F, events []*event.E)

PutEvents stores events in the cache with ZSTD compression This should be called AFTER events are sent to the client

func (*EventCache) PutJSON

func (c *EventCache) PutJSON(f *filter.F, marshaledJSON [][]byte)

PutJSON stores pre-marshaled JSON in the cache with ZSTD compression This should be called AFTER events are sent to the client with the marshaled envelopes

func (*EventCache) Stats

func (c *EventCache) Stats() CacheStats

Stats returns cache statistics

type EventCacheEntry

type EventCacheEntry struct {
	FilterKey        string
	CompressedData   []byte // ZSTD compressed serialized JSON events
	UncompressedSize int    // Original size before compression (for stats)
	CompressedSize   int    // Actual compressed size in bytes
	EventCount       int    // Number of events in this entry
	LastAccess       time.Time
	CreatedAt        time.Time
	// contains filtered or unexported fields
}

EventCacheEntry represents a cached set of compressed serialized events for a filter

Source Files

  • event_cache.go

Jump to

Keyboard shortcuts

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