Browse Source

different cache instance for different store

RockyJin 5 years atrás
parent
commit
a26f1899b4
1 changed files with 11 additions and 4 deletions
  1. 11 4
      common/util.go

+ 11 - 4
common/util.go

@@ -119,14 +119,21 @@ type SimpleKVStore struct {
 	c *cache.Cache;
 }
 
-var sStore *SimpleKVStore
+
+var stores = make(map[string]*SimpleKVStore)
 
 func GetSimpleKVStore(path string) *SimpleKVStore {
-	if sStore == nil {
+	if s, ok := stores[path]; ok {
+		return s
+	} else {
 		c := cache.New(cache.NoExpiration, 0)
-		sStore = &SimpleKVStore{path: path, c: c}
+		if _, err := os.Stat(path); os.IsNotExist(err) {
+			os.MkdirAll(path, os.ModePerm)
+		}
+		sStore := &SimpleKVStore{path: path + "/stores.data", c: c}
+		stores[path] = sStore
+		return sStore
 	}
-	return sStore
 }
 
 func (m *SimpleKVStore) Open() error  {