cache

package
v0.80.1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package cache provides the cache service interface for AI agents. This interface is consumed by Team B (Assistant+Schedule) and Team C (Memo Enhancement).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheService

type CacheService interface {
	// Get retrieves a value from cache.
	// Returns: value, whether it exists
	Get(ctx context.Context, key string) ([]byte, bool)

	// Set stores a value in cache.
	// ttl: expiration time
	Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

	// Invalidate invalidates cache entries.
	// pattern: supports wildcards (user:123:*)
	Invalidate(ctx context.Context, pattern string) error
}

Consumers: Team B (Assistant+Schedule), Team C (Memo Enhancement).

type LRUCache

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

LRUCache implements an LRU cache with TTL support.

func NewLRUCache

func NewLRUCache(capacity int, defaultTTL time.Duration) *LRUCache

NewLRUCache creates a new LRU cache.

func (*LRUCache) CleanupExpired

func (c *LRUCache) CleanupExpired() int

CleanupExpired removes all expired entries. Returns the number of entries removed.

func (*LRUCache) Clear

func (c *LRUCache) Clear()

Clear removes all entries from the cache.

func (*LRUCache) Get

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

Get retrieves a value from the cache.

func (*LRUCache) Invalidate

func (c *LRUCache) Invalidate(pattern string) int

Invalidate removes entries matching the pattern. Supports * wildcard at the end (e.g., "user:123:*").

func (*LRUCache) Set

func (c *LRUCache) Set(key string, value []byte, ttl time.Duration)

Set stores a value in the cache.

func (*LRUCache) Size

func (c *LRUCache) Size() int

Size returns the number of entries in the cache.

type MockCacheService

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

MockCacheService is a mock implementation of CacheService for testing.

func NewMockCacheService

func NewMockCacheService() *MockCacheService

NewMockCacheService creates a new MockCacheService.

func (*MockCacheService) Clear

func (m *MockCacheService) Clear()

Clear removes all items from the cache (for testing).

func (*MockCacheService) Get

func (m *MockCacheService) Get(ctx context.Context, key string) ([]byte, bool)

Get retrieves a value from cache.

func (*MockCacheService) Invalidate

func (m *MockCacheService) Invalidate(ctx context.Context, pattern string) error

Invalidate invalidates cache entries.

func (*MockCacheService) Set

func (m *MockCacheService) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

Set stores a value in cache.

func (*MockCacheService) Size

func (m *MockCacheService) Size() int

Size returns the number of items in the cache (for testing).

type Service

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

Service implements CacheService with LRU eviction.

func NewService

func NewService(cfg ServiceConfig) *Service

NewService creates a new cache service.

func (*Service) Clear

func (s *Service) Clear()

Clear removes all entries from the cache.

func (*Service) Close

func (s *Service) Close()

Close stops the cache service.

func (*Service) Get

func (s *Service) Get(_ context.Context, key string) ([]byte, bool)

Get retrieves a value from cache.

func (*Service) Invalidate

func (s *Service) Invalidate(_ context.Context, pattern string) error

Invalidate invalidates cache entries matching the pattern.

func (*Service) Set

func (s *Service) Set(_ context.Context, key string, value []byte, ttl time.Duration) error

Set stores a value in cache.

func (*Service) Size

func (s *Service) Size() int

Size returns the number of entries in the cache.

type ServiceConfig

type ServiceConfig struct {
	Capacity        int           // Maximum number of entries (default: 1000)
	DefaultTTL      time.Duration // Default TTL for entries (default: 5 minutes)
	CleanupInterval time.Duration // Interval for expired entry cleanup (default: 1 minute)
}

ServiceConfig configures the cache service.

func DefaultServiceConfig

func DefaultServiceConfig() ServiceConfig

DefaultServiceConfig returns default cache service configuration.

Jump to

Keyboard shortcuts

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