From da231b3918349c4898a78c3b8e4a7924cb867b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Thu, 30 Dec 2021 00:56:51 -0500 Subject: [PATCH] Implemented persistent program cache --- cache/cache.go | 8 +++++--- superhighway84.go | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index bd92b4a..22f9a02 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -8,14 +8,16 @@ import ( ) type Cache struct { - db *buntdb.DB + db *buntdb.DB + dbPath string } -func NewCache() (*Cache, error) { +func NewCache(dbPath string) (*Cache, error) { var err error cache := new(Cache) - cache.db, err = buntdb.Open(":memory:") + cache.dbPath = dbPath + cache.db, err = buntdb.Open(cache.dbPath) if err != nil { return nil, err } diff --git a/superhighway84.go b/superhighway84.go index 567aee3..a2936be 100644 --- a/superhighway84.go +++ b/superhighway84.go @@ -62,7 +62,7 @@ func main() { log.Panicln(err) } - cch, err := cache.NewCache() + cch, err := cache.NewCache(cfg.ProgramCachePath) if err != nil { log.Panicln(err) } @@ -77,7 +77,6 @@ func main() { TUI.ArticlesDatasource = &articles TUI.ArticlesRoots = &articlesRoots - db, err := database.NewDatabase(ctx, cfg.ConnectionString, cfg.DatabaseCachePath, cch, logger) if err != nil { log.Panicln(err)