cache

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchLoadOptions

type BatchLoadOptions struct {
	MaxBatches    int
	MaxResults    int
	SkipHotCache  bool
	QueryFilter   *securestorage.QueryOptions
	BatchSize     int  // Override default batch size
	ParallelLoad  bool // Enable parallel batch loading
	CacheBatches  bool // Cache loaded batches temporarily
	RetryAttempts int  // Number of retry attempts for failed batches
}

BatchLoadOptions controls batch loading behavior

type Cache

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

Cache provides a hybrid memory cache for command records with hot cache and batch loading

func NewCache

func NewCache(cfg *config.CacheConfig, storage *securestorage.SecureStorage) *Cache

NewCache creates a new hybrid memory cache instance

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all entries from the cache securely

func (*Cache) Close

func (c *Cache) Close() error

Close safely shuts down the cache

func (*Cache) EvictOldEntries

func (c *Cache) EvictOldEntries()

EvictOldEntries removes entries based on the configured eviction policy

func (*Cache) GetHotCacheAge

func (c *Cache) GetHotCacheAge() time.Duration

GetHotCacheAge returns how long since the hot cache was last refreshed

func (*Cache) GetSecurityInfo

func (c *Cache) GetSecurityInfo() map[string]interface{}

GetSecurityInfo returns information about secure memory handling

func (*Cache) GetStats

func (c *Cache) GetStats() *CacheStats

GetStats returns cache performance statistics

func (*Cache) IsHotCacheValid

func (c *Cache) IsHotCacheValid() bool

IsHotCacheValid checks if the hot cache is still valid

func (*Cache) LoadHotCache

func (c *Cache) LoadHotCache() error

LoadHotCache loads the most recent commands into the hot cache

func (*Cache) LoadHotCacheWithOptions

func (c *Cache) LoadHotCacheWithOptions(opts *HotCacheLoadOptions) error

LoadHotCacheWithOptions loads the hot cache with specific options

func (*Cache) RefreshIfNeeded

func (c *Cache) RefreshIfNeeded() error

RefreshIfNeeded refreshes the hot cache if the refresh interval has passed

func (*Cache) Search

func (c *Cache) Search(query string, opts *BatchLoadOptions) (*SearchResult, error)

Search performs a search operation using hot cache and batch loading

func (*Cache) SetEvictionPolicy

func (c *Cache) SetEvictionPolicy(policy EvictionPolicy)

SetEvictionPolicy changes the cache eviction policy

func (*Cache) SetMaxCacheAge

func (c *Cache) SetMaxCacheAge(maxAge time.Duration)

SetMaxCacheAge sets the maximum age for cache entries

func (*Cache) SetSecurityLevel

func (c *Cache) SetSecurityLevel(level int)

SetSecurityLevel configures the memory security level

func (*Cache) StartBackgroundRefresh

func (c *Cache) StartBackgroundRefresh()

StartBackgroundRefresh starts automatic cache refresh

func (*Cache) StartCacheMaintenance

func (c *Cache) StartCacheMaintenance()

StartCacheMaintenance starts automatic cache maintenance

func (*Cache) StopBackgroundRefresh

func (c *Cache) StopBackgroundRefresh()

StopBackgroundRefresh stops automatic cache refresh

func (*Cache) StopCacheMaintenance

func (c *Cache) StopCacheMaintenance()

StopCacheMaintenance stops automatic cache maintenance

func (*Cache) WarmUpCache

func (c *Cache) WarmUpCache() error

WarmUpCache preloads the cache for better performance

type CacheEntry

type CacheEntry struct {
	Record      *storage.CommandRecord
	AccessTime  time.Time
	AccessCount int64
	InsertTime  time.Time
	Size        int64
}

CacheEntry wraps a command record with metadata for eviction policies

type CacheStats

type CacheStats struct {
	HotCacheSize    int           `json:"hot_cache_size"`
	CurrentMemoryMB int64         `json:"current_memory_mb"`
	CacheHits       int64         `json:"cache_hits"`
	CacheMisses     int64         `json:"cache_misses"`
	BatchesLoaded   int64         `json:"batches_loaded"`
	LastRefresh     time.Time     `json:"last_refresh"`
	RefreshInterval time.Duration `json:"refresh_interval"`
	HitRatio        float64       `json:"hit_ratio"`
}

CacheStats provides cache performance statistics

type EvictionPolicy

type EvictionPolicy int

EvictionPolicy defines the cache eviction strategy

const (
	EvictionLRU  EvictionPolicy = iota // Least Recently Used
	EvictionLFU                        // Least Frequently Used
	EvictionTTL                        // Time To Live based
	EvictionSize                       // Size based (oldest entries)
)

type HotCacheLoadOptions

type HotCacheLoadOptions struct {
	Size           int        `json:"size"`
	ForceRefresh   bool       `json:"force_refresh"`
	SessionFilter  string     `json:"session_filter"`
	HostnameFilter string     `json:"hostname_filter"`
	SinceTime      *time.Time `json:"since_time"`
}

HotCacheLoadOptions provides options for loading the hot cache

type SearchResult

type SearchResult struct {
	Records      []*storage.CommandRecord `json:"records"`
	TotalMatches int                      `json:"total_matches"`
	FromCache    int                      `json:"from_cache"`
	FromBatches  int                      `json:"from_batches"`
	SearchTime   time.Duration            `json:"search_time"`
}

SearchResult contains search results with metadata

Jump to

Keyboard shortcuts

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