Documentation
¶
Overview ¶
Package cache provides caching for parsed schemas and query ASTs.
Package cache provides caching infrastructure for db-catalyst.
The cache package defines a generic Cache interface and provides implementations for in-memory caching. It's used to speed up incremental builds by caching parsed schemas and query analyses.
Usage:
c := cache.NewMemoryCache()
c.Set(ctx, "key", value, time.Hour)
if val, ok := c.Get(ctx, "key"); ok {
// use cached value
}
Index ¶
- func ComputeKey(content []byte) string
- func ComputeKeyWithPrefix(prefix string, content []byte) string
- type Cache
- type Entry
- type FileCache
- func (f *FileCache) Cleanup()
- func (f *FileCache) Clear(_ context.Context)
- func (f *FileCache) Delete(_ context.Context, key string)
- func (f *FileCache) Get(_ context.Context, key string) (any, bool)
- func (f *FileCache) Set(_ context.Context, key string, value any, ttl time.Duration)
- func (f *FileCache) Stats() (total int, expired int, size int64)
- type Keyable
- type MemoryCache
- func (m *MemoryCache) Cleanup()
- func (m *MemoryCache) Clear(_ context.Context)
- func (m *MemoryCache) Delete(_ context.Context, key string)
- func (m *MemoryCache) Get(_ context.Context, key string) (any, bool)
- func (m *MemoryCache) Len() int
- func (m *MemoryCache) Set(_ context.Context, key string, value any, ttl time.Duration)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComputeKey ¶
ComputeKey generates a cache key from content using SHA-256.
func ComputeKeyWithPrefix ¶
ComputeKeyWithPrefix generates a cache key with a prefix.
Types ¶
type Cache ¶
type Cache interface {
Get(ctx context.Context, key string) (any, bool)
Set(ctx context.Context, key string, value any, ttl time.Duration)
Delete(ctx context.Context, key string)
Clear(ctx context.Context)
}
Cache provides a generic caching interface.
type FileCache ¶
type FileCache struct {
// contains filtered or unexported fields
}
FileCache implements Cache using file system storage. It stores cache entries as JSON files in a directory structure.
func NewFileCache ¶
NewFileCache creates a new file-based cache. The baseDir is where cache files will be stored.
type Keyable ¶
type Keyable interface {
CacheKey() string
}
Keyable is implemented by types that can provide a cache key.
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache implements Cache using in-memory storage.
func NewMemoryCache ¶
func NewMemoryCache() *MemoryCache
NewMemoryCache creates a new in-memory cache.
func (*MemoryCache) Clear ¶
func (m *MemoryCache) Clear(_ context.Context)
Clear removes all values from the cache.
func (*MemoryCache) Delete ¶
func (m *MemoryCache) Delete(_ context.Context, key string)
Delete removes a value from the cache.
func (*MemoryCache) Len ¶
func (m *MemoryCache) Len() int
Len returns the number of items in the cache (including expired).