Documentation
¶
Overview ¶
Package cache stores downloaded artifacts and their scan results.
Index ¶
- type Cache
- type CacheEntry
- type CacheStats
- type Index
- func (idx *Index) Close() error
- func (idx *Index) Count() (int64, error)
- func (idx *Index) Delete(ref *gate.PackageRef) error
- func (idx *Index) DueForRevalidation(before int64, limit int) ([]RevalEntry, error)
- func (idx *Index) Get(ref *gate.PackageRef) (*CacheEntry, bool)
- func (idx *Index) IncrementHit(ref *gate.PackageRef) error
- func (idx *Index) Insert(ref *gate.PackageRef, entry *CacheEntry) error
- func (idx *Index) LRUCandidates(n int) ([]gate.PackageRef, error)
- func (idx *Index) MarkValidated(ref *gate.PackageRef, ts int64) error
- func (idx *Index) TotalSizeBytes() (int64, error)
- type LocalCache
- func (lc *LocalCache) Close() error
- func (lc *LocalCache) DueForRevalidation(before int64, limit int) ([]RevalEntry, error)
- func (lc *LocalCache) Get(ref *gate.PackageRef) (*CacheEntry, bool)
- func (lc *LocalCache) Invalidate(ref *gate.PackageRef) error
- func (lc *LocalCache) MarkValidated(ref *gate.PackageRef, ts int64) error
- func (lc *LocalCache) Put(ref *gate.PackageRef, tmpPath string, scanClean bool, scanJSON string) error
- func (lc *LocalCache) Stats() (CacheStats, error)
- type LocalCacheConfig
- type RevalEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
// Get returns the cached entry for ref, or (nil, false) on miss or expiry.
Get(ref *gate.PackageRef) (*CacheEntry, bool)
// Put copies the artifact at tmpPath into the cache store and records the scan result.
Put(ref *gate.PackageRef, tmpPath string, scanClean bool, scanJSON string) error
// Invalidate removes the cached entry and its artifact file for ref.
Invalidate(ref *gate.PackageRef) error
// Stats returns aggregate cache statistics.
Stats() (CacheStats, error)
// Close stops background workers and releases the index.
Close() error
}
Cache is the storage interface for package artifacts and scan results.
type CacheEntry ¶
type CacheEntry struct {
// ArtifactPath is the absolute path to the cached file on disk.
ArtifactPath string
// ScanClean is true if all scanners passed.
ScanClean bool
// ScanJSON stores the serialized ScanResult for future inspection.
ScanJSON string
StoredAt time.Time
ExpiresAt time.Time
HitCount int64
SizeBytes int64
}
CacheEntry stores an artifact path and its scan results.
func (*CacheEntry) IsExpired ¶
func (e *CacheEntry) IsExpired() bool
IsExpired returns true if the entry TTL has elapsed.
type CacheStats ¶
CacheStats holds aggregate statistics about the cache.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index manages the SQLite-backed metadata index for the local cache.
func (*Index) Delete ¶
func (idx *Index) Delete(ref *gate.PackageRef) error
Delete removes an entry from the index.
func (*Index) DueForRevalidation ¶
func (idx *Index) DueForRevalidation(before int64, limit int) ([]RevalEntry, error)
DueForRevalidation returns up to limit non-expired entries whose last_validated is older than `before` (a unix timestamp), oldest-first. Expired entries are excluded — they are dropped on access anyway.
func (*Index) Get ¶
func (idx *Index) Get(ref *gate.PackageRef) (*CacheEntry, bool)
Get retrieves a cache entry. Returns (nil, false) if not found or expired.
func (*Index) IncrementHit ¶
func (idx *Index) IncrementHit(ref *gate.PackageRef) error
IncrementHit bumps the hit counter and updates last_hit timestamp.
func (*Index) Insert ¶
func (idx *Index) Insert(ref *gate.PackageRef, entry *CacheEntry) error
Insert adds or updates a cache entry (UPSERT semantics).
func (*Index) LRUCandidates ¶
func (idx *Index) LRUCandidates(n int) ([]gate.PackageRef, error)
LRUCandidates returns up to n entries sorted by last_hit ascending (LRU first).
func (*Index) MarkValidated ¶
func (idx *Index) MarkValidated(ref *gate.PackageRef, ts int64) error
MarkValidated sets last_validated for ref to ts (a unix timestamp).
func (*Index) TotalSizeBytes ¶
TotalSizeBytes returns the sum of size_bytes for all entries.
type LocalCache ¶
type LocalCache struct {
// contains filtered or unexported fields
}
LocalCache implements Cache using the local filesystem with a SQLite index.
func NewLocalCache ¶
func NewLocalCache(cfg LocalCacheConfig) (*LocalCache, error)
NewLocalCache creates a LocalCache rooted at cfg.RootPath.
func (*LocalCache) Close ¶
func (lc *LocalCache) Close() error
Close stops the eviction worker and closes the index. Safe to call twice.
func (*LocalCache) DueForRevalidation ¶
func (lc *LocalCache) DueForRevalidation(before int64, limit int) ([]RevalEntry, error)
DueForRevalidation returns cached entries due for re-validation. See Index.
func (*LocalCache) Get ¶
func (lc *LocalCache) Get(ref *gate.PackageRef) (*CacheEntry, bool)
Get returns a cached entry, or (nil, false) on miss or expiry.
func (*LocalCache) Invalidate ¶
func (lc *LocalCache) Invalidate(ref *gate.PackageRef) error
Invalidate removes an entry from both the index and disk.
func (*LocalCache) MarkValidated ¶
func (lc *LocalCache) MarkValidated(ref *gate.PackageRef, ts int64) error
MarkValidated records that ref passed re-validation at ts (unix seconds).
func (*LocalCache) Put ¶
func (lc *LocalCache) Put(ref *gate.PackageRef, tmpPath string, scanClean bool, scanJSON string) error
Put copies the artifact from tmpPath into the cache store and records scan results.
func (*LocalCache) Stats ¶
func (lc *LocalCache) Stats() (CacheStats, error)
Stats returns aggregate cache statistics.
type LocalCacheConfig ¶
LocalCacheConfig configures the local filesystem cache.
type RevalEntry ¶
type RevalEntry struct {
Ref gate.PackageRef
FilePath string
ScanClean bool
ScanJSON string
}
RevalEntry is a cached entry presented to the re-validation sweep. It carries just enough to re-run the gates: the package ref, the artifact bytes on disk, and the prior verdict.