Documentation
¶
Index ¶
- Variables
- type CacheStats
- type MemoryQueryCache
- func (m *MemoryQueryCache) Clear()
- func (m *MemoryQueryCache) Close()
- func (m *MemoryQueryCache) Delete(key string)
- func (m *MemoryQueryCache) Get(key string) ([]*SearchResult, bool)
- func (m *MemoryQueryCache) Len() int
- func (m *MemoryQueryCache) Set(key string, results []*SearchResult, ttl time.Duration)
- type QueryCache
- func (c *QueryCache) Clear(ctx context.Context) error
- func (c *QueryCache) Delete(ctx context.Context, req *SearchRequest) error
- func (c *QueryCache) Disable()
- func (c *QueryCache) Enable()
- func (c *QueryCache) Get(ctx context.Context, req *SearchRequest) ([]*SearchResult, error)
- func (c *QueryCache) GetStats() *CacheStats
- func (c *QueryCache) IsEnabled() bool
- func (c *QueryCache) Set(ctx context.Context, req *SearchRequest, results []*SearchResult) error
- type RedisClient
- type SearchRequest
- type SearchResult
Constants ¶
This section is empty.
Variables ¶
var ( // ErrQueryNotFound indicates query result not found in cache. ErrQueryNotFound = errors.New("query result not found in cache") )
Functions ¶
This section is empty.
Types ¶
type CacheStats ¶
CacheStats represents cache statistics.
func (*CacheStats) HitRate ¶
func (s *CacheStats) HitRate() float64
HitRate returns the cache hit rate.
type MemoryQueryCache ¶
type MemoryQueryCache struct {
// contains filtered or unexported fields
}
MemoryQueryCache provides in-memory caching for query results.
func NewMemoryQueryCache ¶
func NewMemoryQueryCache() *MemoryQueryCache
NewMemoryQueryCache creates a new in-memory query cache. The cleanup goroutine runs periodically to remove expired items.
func (*MemoryQueryCache) Clear ¶
func (m *MemoryQueryCache) Clear()
Clear removes all items from cache.
func (*MemoryQueryCache) Close ¶
func (m *MemoryQueryCache) Close()
Close stops the cleanup goroutine and cleans up resources. This should be called when the cache is no longer needed to prevent goroutine leaks.
func (*MemoryQueryCache) Delete ¶
func (m *MemoryQueryCache) Delete(key string)
Delete removes search results from cache.
func (*MemoryQueryCache) Get ¶
func (m *MemoryQueryCache) Get(key string) ([]*SearchResult, bool)
Get retrieves search results from cache.
func (*MemoryQueryCache) Len ¶
func (m *MemoryQueryCache) Len() int
Len returns the number of items in cache.
func (*MemoryQueryCache) Set ¶
func (m *MemoryQueryCache) Set(key string, results []*SearchResult, ttl time.Duration)
Set stores search results in cache.
type QueryCache ¶
type QueryCache struct {
// contains filtered or unexported fields
}
QueryCache provides caching for query results to bypass DB and embedding calls. It supports both Redis and in-memory cache with automatic fallback.
func NewQueryCache ¶
func NewQueryCache(redisClient RedisClient, ttl time.Duration) *QueryCache
NewQueryCache creates a new query cache. redisClient is optional. If nil, it will use in-memory cache only.
func (*QueryCache) Clear ¶
func (c *QueryCache) Clear(ctx context.Context) error
Clear removes all query results from cache.
func (*QueryCache) Delete ¶
func (c *QueryCache) Delete(ctx context.Context, req *SearchRequest) error
Delete removes a query result from cache.
func (*QueryCache) Get ¶
func (c *QueryCache) Get(ctx context.Context, req *SearchRequest) ([]*SearchResult, error)
Get retrieves cached search results.
func (*QueryCache) GetStats ¶
func (c *QueryCache) GetStats() *CacheStats
GetStats returns cache statistics.
func (*QueryCache) IsEnabled ¶
func (c *QueryCache) IsEnabled() bool
IsEnabled returns whether the cache is enabled.
func (*QueryCache) Set ¶
func (c *QueryCache) Set(ctx context.Context, req *SearchRequest, results []*SearchResult) error
Set stores search results in cache.
type RedisClient ¶
type RedisClient interface {
Get(ctx context.Context, key string) (string, error)
Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error
Del(ctx context.Context, keys ...string) error
Keys(ctx context.Context, pattern string) ([]string, error)
}
RedisClient defines the interface for Redis operations.
type SearchRequest ¶
SearchRequest represents a search request.