From 0a4929876c1606abf2a599c6561affba368ab5fb Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Tue, 28 Nov 2017 22:38:21 +0100 Subject: Add caching --- main.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'main.go') diff --git a/main.go b/main.go index 11202f3..5ea627f 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "code.laria.me/petrific/cache" "code.laria.me/petrific/config" "code.laria.me/petrific/storage" "code.laria.me/petrific/storage/registry" @@ -44,6 +45,7 @@ var ( var conf config.Config var objectstore storage.Storage +var id_cache cache.Cache = cache.NopCache{} func main() { os.Exit(Main()) @@ -64,6 +66,11 @@ func Main() int { } defer objectstore.Close() + if !loadCache(conf) { + return 1 + } + defer id_cache.Close() + remaining := make([]string, 0) for _, arg := range flag.Args() { if arg != "" { @@ -84,6 +91,22 @@ func Main() int { return cmd(remaining[1:]) } +func loadCache(conf config.Config) bool { + if conf.CachePath == "" { + return true + } + + file_cache := cache.NewFileCache(config.ExpandTilde(conf.CachePath)) + if err := file_cache.Load(); err != nil { + fmt.Fprintf(os.Stderr, "Loading cache %s: %s", conf.CachePath, err) + return false + } + + id_cache = file_cache + + return true +} + func loadConfig() bool { var err error conf, err = config.LoadConfig(*flagConfPath) -- cgit v1.2.3-54-g00ecf