mirror of
https://github.com/kopia/kopia.git
synced 2026-05-11 00:04:46 -04:00
* test(providers): added capacity limits to blobtesting.mapStorage * refactor(general): added mutex map which dynamically allocates and releases named mutexes * refactor(repository): refactored cache cleanup and limit enforcement * refactor(repository): plumb through cache size limits in the repository * feat(cli): added CLI options to set cache size limits * unified flag setting and field naming * Update cli/command_cache_set.go Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com> * pr feedback --------- Co-authored-by: Shikhar Mall <mall.shikhar.in@gmail.com>
67 lines
2.1 KiB
Go
67 lines
2.1 KiB
Go
package content
|
|
|
|
import (
|
|
"path/filepath"
|
|
"time"
|
|
)
|
|
|
|
// DurationSeconds represents the duration in seconds.
|
|
type DurationSeconds float64
|
|
|
|
// DurationOrDefault returns the duration or the provided default if not set or zero.
|
|
func (s DurationSeconds) DurationOrDefault(def time.Duration) time.Duration {
|
|
if s == 0 {
|
|
return def
|
|
}
|
|
|
|
return time.Duration(float64(s) * float64(time.Second))
|
|
}
|
|
|
|
// CachingOptions specifies configuration of local cache.
|
|
type CachingOptions struct {
|
|
CacheDirectory string `json:"cacheDirectory,omitempty"`
|
|
ContentCacheSizeBytes int64 `json:"maxCacheSize,omitempty"`
|
|
ContentCacheSizeLimitBytes int64 `json:"contentCacheSizeLimitBytes,omitempty"`
|
|
MetadataCacheSizeBytes int64 `json:"maxMetadataCacheSize,omitempty"`
|
|
MetadataCacheSizeLimitBytes int64 `json:"metadataCacheSizeLimitBytes,omitempty"`
|
|
MaxListCacheDuration DurationSeconds `json:"maxListCacheDuration,omitempty"`
|
|
MinMetadataSweepAge DurationSeconds `json:"minMetadataSweepAge,omitempty"`
|
|
MinContentSweepAge DurationSeconds `json:"minContentSweepAge,omitempty"`
|
|
MinIndexSweepAge DurationSeconds `json:"minIndexSweepAge,omitempty"`
|
|
HMACSecret []byte `json:"-"`
|
|
}
|
|
|
|
// EffectiveMetadataCacheSizeBytes returns the effective metadata cache size.
|
|
func (c *CachingOptions) EffectiveMetadataCacheSizeBytes() int64 {
|
|
if c.MetadataCacheSizeBytes == 0 {
|
|
// legacy path, use the same size for both caches.
|
|
return c.ContentCacheSizeBytes
|
|
}
|
|
|
|
return c.MetadataCacheSizeBytes
|
|
}
|
|
|
|
// CloneOrDefault returns a clone of the caching options or empty options for nil.
|
|
func (c *CachingOptions) CloneOrDefault() *CachingOptions {
|
|
if c == nil {
|
|
return &CachingOptions{}
|
|
}
|
|
|
|
c2 := *c
|
|
|
|
return &c2
|
|
}
|
|
|
|
// CacheSubdirOrEmpty returns path to a cache subdirectory or empty string if cache is disabled.
|
|
func (c *CachingOptions) CacheSubdirOrEmpty(subdir string) string {
|
|
if c == nil {
|
|
return ""
|
|
}
|
|
|
|
if c.CacheDirectory == "" {
|
|
return ""
|
|
}
|
|
|
|
return filepath.Join(c.CacheDirectory, subdir)
|
|
}
|