Documentation
¶
Overview ¶
Package cache provides cache key generation and formatting for compilation results
CRITICAL INVARIANT: SORTED ORDER REQUIREMENT All cache keys MUST be generated with inputs sorted in a consistent order. This ensures that identical compilations produce identical cache keys regardless of input order.
Sorted components:
- Proto files: sorted by Path (string comparison)
- Dependencies: sorted by ModuleName, then Version
- Dependency proto files: sorted by Path
- Options map: keys sorted alphabetically before hashing
CHANGING THESE SORT ORDERS WILL INVALIDATE THE ENTIRE CACHE ¶
Cache Key Format Version: v1 Format: {moduleName}:{version}:{language}:{pluginVersion}:{protoHash}:{optionsHash}
DO NOT modify generateProtoHash(), hashOptions(), or FormatCacheKey() without: 1. Incrementing cache format version 2. Clearing all existing cached compilations 3. Updating cache migration documentation
Index ¶
- Variables
- func FormatCacheKey(key *codegen.CacheKey) string
- func GenerateCacheKey(moduleName, version, language, pluginVersion string, ...) *codegen.CacheKey
- func GetKeyString(key *codegen.CacheKey) string
- func ValidateCacheKey(key *codegen.CacheKey) error
- type Config
- type MemoryCache
- func (c *MemoryCache) Close() error
- func (c *MemoryCache) Delete(ctx context.Context, key *codegen.CacheKey) error
- func (c *MemoryCache) Get(ctx context.Context, key *codegen.CacheKey) (*codegen.CompilationResult, error)
- func (c *MemoryCache) Invalidate(ctx context.Context, moduleName, version string) error
- func (c *MemoryCache) Set(ctx context.Context, key *codegen.CacheKey, result *codegen.CompilationResult, ...) error
- func (c *MemoryCache) Stats(ctx context.Context) (*Stats, error)
- type Stats
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCacheMiss is returned when a cache key is not found ErrCacheMiss = errors.New("cache miss") ErrCacheUnavailable = errors.New("cache unavailable") // ErrInvalidCacheKey is returned when a cache key is invalid ErrInvalidCacheKey = errors.New("invalid cache key") // ErrCacheFull is returned when the cache is full ErrCacheFull = errors.New("cache full") )
Functions ¶
func FormatCacheKey ¶
FormatCacheKey formats a cache key as a string for storage
Cache Key Format Version: v1 Format: {moduleName}:{version}:{language}:{pluginVersion}:{protoHash}:{optionsHash}
CRITICAL: This is the single source of truth for cache key string format. The codegen.CacheKey.String() method delegates to this function.
CHANGING THIS FORMAT INVALIDATES ALL CACHED COMPILATIONS If you must change it: 1. Increment version number in package documentation 2. Clear all cached data (or implement migration) 3. Update cache documentation
func GenerateCacheKey ¶
func GenerateCacheKey(moduleName, version, language, pluginVersion string, protoFiles []codegen.ProtoFile, dependencies []codegen.Dependency, options map[string]string) *codegen.CacheKey
GenerateCacheKey generates a cache key from compilation parameters
IMPORTANT: This function ensures deterministic key generation by sorting all inputs. DO NOT call with pre-sorted inputs assuming you're helping - the sorting is intentional and must happen in this function to guarantee consistency.
func GetKeyString ¶
GetKeyString returns the cache key as a string (helper for codegen.CacheKey.String())
func ValidateCacheKey ¶
ValidateCacheKey validates a cache key
Types ¶
type Config ¶
type Config struct {
MaxSize int64 // Max size in bytes (default: 100MB)
TTL time.Duration // TTL for cache entries (default: 5 minutes)
}
Config holds cache configuration
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache implements a simple in-memory LRU cache
func NewCache ¶
func NewCache(config *Config) (*MemoryCache, error)
NewCache creates a new memory-only cache
func (*MemoryCache) Get ¶
func (c *MemoryCache) Get(ctx context.Context, key *codegen.CacheKey) (*codegen.CompilationResult, error)
Get retrieves a cached compilation result
func (*MemoryCache) Invalidate ¶
func (c *MemoryCache) Invalidate(ctx context.Context, moduleName, version string) error
Invalidate removes all cached results for a module/version