Documentation
¶
Overview ¶
Package cache provides in-memory and disk caching for NuGet operations.
Index ¶
- Constants
- func ComputeHash(value string, addIdentifiableCharacters bool) string
- func RemoveInvalidFileNameChars(value string) string
- func WithCacheContext(ctx context.Context, cacheCtx *SourceCacheContext) context.Context
- type DiskCache
- func (dc *DiskCache) Clear() error
- func (dc *DiskCache) Delete(sourceURL string, cacheKey string) error
- func (dc *DiskCache) Get(sourceURL string, cacheKey string, maxAge time.Duration) (io.ReadCloser, bool, error)
- func (dc *DiskCache) GetCachePath(sourceURL string, cacheKey string) (cacheFile string, newFile string)
- func (dc *DiskCache) Set(sourceURL string, cacheKey string, data io.Reader, ...) error
- type Entry
- type MemoryCache
- type MultiTierCache
- type SourceCacheContext
- type Stats
Constants ¶
const ( // HashLength is the number of bytes to use from the SHA256 hash. // Set to 20 to maintain backwards compatibility with SHA-1 length. HashLength = 20 // BufferSize for file I/O operations (matches NuGet.Client). BufferSize = 8192 // CacheFileExtension for final cache files. CacheFileExtension = ".dat" // NewFileExtension for temporary files during atomic write. NewFileExtension = ".dat-new" )
Variables ¶
This section is empty.
Functions ¶
func ComputeHash ¶
ComputeHash computes a hash for the given value. Matches NuGet.Client's CachingUtility.ComputeHash exactly.
func RemoveInvalidFileNameChars ¶
RemoveInvalidFileNameChars replaces invalid filename characters with underscores. Matches NuGet.Client's CachingUtility.RemoveInvalidFileNameChars.
func WithCacheContext ¶
func WithCacheContext(ctx context.Context, cacheCtx *SourceCacheContext) context.Context
WithCacheContext adds the source cache context to the Go context. This allows protocol layer code to respect cache control flags without passing SourceCacheContext through every function.
Types ¶
type DiskCache ¶
type DiskCache struct {
// contains filtered or unexported fields
}
DiskCache provides persistent caching to disk.
func NewDiskCache ¶
NewDiskCache creates a new disk cache. If rootDir is empty, cache operations are disabled (NoCache mode).
func (*DiskCache) Get ¶
func (dc *DiskCache) Get(sourceURL string, cacheKey string, maxAge time.Duration) (io.ReadCloser, bool, error)
Get retrieves a cached file if it exists and is not expired. Returns (reader, true) if found and valid, (nil, false) otherwise. In NoCache mode (empty rootDir), always returns cache miss.
func (*DiskCache) GetCachePath ¶
func (dc *DiskCache) GetCachePath(sourceURL string, cacheKey string) (cacheFile string, newFile string)
GetCachePath computes the cache file path for a source URL and cache key. Matches NuGet.Client's HttpCacheUtility.InitializeHttpCacheResult.
func (*DiskCache) Set ¶
func (dc *DiskCache) Set(sourceURL string, cacheKey string, data io.Reader, validate func(io.ReadSeeker) error) error
Set writes data to the cache using atomic two-phase update. Matches NuGet.Client's HttpCacheUtility.CreateCacheFileAsync. In NoCache mode (empty rootDir), this is a no-op.
type Entry ¶
type Entry struct {
Value []byte
Expiry time.Time
Size int
// contains filtered or unexported fields
}
Entry represents a cached value with metadata.
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache is an LRU cache with TTL support.
func NewMemoryCache ¶
func NewMemoryCache(maxEntries int, maxSize int64) *MemoryCache
NewMemoryCache creates a new LRU memory cache.
func (*MemoryCache) Clear ¶
func (mc *MemoryCache) Clear()
Clear removes all entries from the cache. This matches NuGet.Client's RefreshMemoryCache behavior.
func (*MemoryCache) Delete ¶
func (mc *MemoryCache) Delete(key string)
Delete removes a key from the cache.
func (*MemoryCache) Get ¶
func (mc *MemoryCache) Get(key string) ([]byte, bool)
Get retrieves a value from the cache. Returns (value, true) if found and not expired, (nil, false) otherwise.
type MultiTierCache ¶
type MultiTierCache struct {
// contains filtered or unexported fields
}
MultiTierCache combines memory (L1) and disk (L2) caching with automatic promotion. When data is found in L2, it's promoted to L1 for faster subsequent access.
func NewMultiTierCache ¶
func NewMultiTierCache(l1 *MemoryCache, l2 *DiskCache) *MultiTierCache
NewMultiTierCache creates a new multi-tier cache combining memory and disk layers.
type SourceCacheContext ¶
type SourceCacheContext struct {
// MaxAge is the maximum age for cached entries (default: 30 minutes)
MaxAge time.Duration
// NoCache bypasses the global disk cache if true
NoCache bool
// DirectDownload skips cache writes (read-only mode)
DirectDownload bool
// RefreshMemoryCache forces in-memory cache reload
RefreshMemoryCache bool
// SessionID is a unique identifier for the session (X-NuGet-Session-Id header)
SessionID string
}
SourceCacheContext provides cache control settings matching NuGet.Client behavior.
func FromContext ¶
func FromContext(ctx context.Context) *SourceCacheContext
FromContext retrieves the source cache context from the Go context. Returns nil if no cache context was set.
func NewSourceCacheContext ¶
func NewSourceCacheContext() *SourceCacheContext
NewSourceCacheContext creates a new cache context with defaults.
func (*SourceCacheContext) Clone ¶
func (ctx *SourceCacheContext) Clone() *SourceCacheContext
Clone creates a copy of the cache context.