mirror of
https://github.com/kopia/kopia.git
synced 2026-05-19 04:04:56 -04:00
refactored cache commands
This commit is contained in:
30
cli/command_cache_set.go
Normal file
30
cli/command_cache_set.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/kopia/kopia/repo"
|
||||
"github.com/kopia/kopia/repo/block"
|
||||
)
|
||||
|
||||
var (
|
||||
cacheSetParamsCommand = cacheCommands.Command("set", "Sets parameters local caching of repository data").Hidden()
|
||||
|
||||
cacheSetDirectory = cacheSetParamsCommand.Flag("cache-directory", "Directory where to store cache files").String()
|
||||
cacheSetMaxCacheSizeMB = cacheSetParamsCommand.Flag("cache-size-mb", "Size of local cache (0 disables caching)").PlaceHolder("MB").Int64()
|
||||
cacheSetMaxListCacheDuration = cacheSetParamsCommand.Flag("max-list-cache-duration", "Duration of index cache").Default("600s").Duration()
|
||||
)
|
||||
|
||||
func runCacheSetCommand(ctx context.Context, rep *repo.Repository) error {
|
||||
opts := block.CachingOptions{
|
||||
CacheDirectory: *cacheSetDirectory,
|
||||
MaxCacheSizeBytes: *cacheSetMaxCacheSizeMB << 20,
|
||||
MaxListCacheDurationSec: int(cacheSetMaxListCacheDuration.Seconds()),
|
||||
}
|
||||
|
||||
return repo.SetCachingConfig(ctx, repositoryConfigFileName(), opts)
|
||||
}
|
||||
|
||||
func init() {
|
||||
cacheSetParamsCommand.Action(repositoryAction(runCacheSetCommand))
|
||||
}
|
||||
Reference in New Issue
Block a user