From 4bf34124a3dcb221913367b798e72021e3db7bc6 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sun, 20 Aug 2017 10:09:10 +0100 Subject: [PATCH] Close #207 --- caddy/parser/parser.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/caddy/parser/parser.go b/caddy/parser/parser.go index 697d5584..664cb4a6 100644 --- a/caddy/parser/parser.go +++ b/caddy/parser/parser.go @@ -20,6 +20,8 @@ import ( "github.com/spf13/viper" ) +var databases = map[string]*storm.DB{} + // Parse ... func Parse(c *caddy.Controller, plugin string) ([]*filemanager.FileManager, error) { var ( @@ -190,7 +192,14 @@ func Parse(c *caddy.Controller, plugin string) ([]*filemanager.FileManager, erro u.Scope = scope u.FileSystem = fileutils.Dir(scope) - db, err := storm.Open(database) + var db *storm.DB + if stored, ok := databases[database]; ok { + db = stored + } else { + db, err = storm.Open(database) + databases[database] = db + } + if err != nil { return nil, err }