diff --git a/memcache/memcache.go b/memcache/memcache.go index cab3a5b0..f1cc8137 100644 --- a/memcache/memcache.go +++ b/memcache/memcache.go @@ -98,6 +98,11 @@ func (s *Storage) Clear() error { return s.db.DeleteAll() } +// Close the storage +func (s *Storage) Close() error { + return nil +} + // Acquire item from pool func (s *Storage) acquireItem() *mc.Item { return s.items.Get().(*mc.Item) diff --git a/memory/memory.go b/memory/memory.go index 86bfe1b2..759c2bcb 100644 --- a/memory/memory.go +++ b/memory/memory.go @@ -83,6 +83,11 @@ func (s *Storage) Clear() error { return nil } +// Close the storage +func (s *Storage) Close() error { + return nil +} + func (s *Storage) gc() { for t := range time.NewTicker(s.gcInterval).C { now := t.Unix() diff --git a/mysql/mysql.go b/mysql/mysql.go index 45ea29d1..42670f58 100644 --- a/mysql/mysql.go +++ b/mysql/mysql.go @@ -76,7 +76,7 @@ func New(config ...Config) *Storage { gcInterval: cfg.GCInterval, db: db, sqlSelect: fmt.Sprintf("SELECT data, exp FROM %s WHERE id=?;", cfg.Table), - sqlInsert: fmt.Sprintf("INSERT OR REPLACE INTO %s (id, data, exp) VALUES (?,?,?)", cfg.Table), + sqlInsert: fmt.Sprintf("INSERT INTO %s (id, data, exp) VALUES (?,?,?)", cfg.Table), sqlDelete: fmt.Sprintf("DELETE FROM %s WHERE id=?", cfg.Table), sqlClear: fmt.Sprintf("DELETE FROM %s;", cfg.Table), sqlGC: fmt.Sprintf("DELETE FROM %s WHERE exp <= ?", cfg.Table), @@ -142,6 +142,11 @@ func (s *Storage) Clear() error { return err } +// Close the storage +func (s *Storage) Close() error { + return s.db.Close() +} + // Garbage collector to delete expired keys func (s *Storage) gc() { tick := time.NewTicker(s.gcInterval) diff --git a/postgres/postgres.go b/postgres/postgres.go index abbb8d17..8c971d8a 100644 --- a/postgres/postgres.go +++ b/postgres/postgres.go @@ -158,6 +158,11 @@ func (s *Storage) Clear() error { return err } +// Close the storage +func (s *Storage) Close() error { + return s.db.Close() +} + // GC deletes all expired entries func (s *Storage) gc() { tick := time.NewTicker(s.gcInterval) diff --git a/redis/redis.go b/redis/redis.go index 86497adb..81cedaad 100644 --- a/redis/redis.go +++ b/redis/redis.go @@ -75,3 +75,8 @@ func (s *Storage) Delete(key string) error { func (s *Storage) Clear() error { return s.db.FlushDB(context.Background()).Err() } + +// Close the storage +func (s *Storage) Close() error { + return s.db.Close() +} diff --git a/sqlite3/sqlite3.go b/sqlite3/sqlite3.go index c31f0162..8422d276 100644 --- a/sqlite3/sqlite3.go +++ b/sqlite3/sqlite3.go @@ -141,6 +141,11 @@ func (s *Storage) Clear() error { return err } +// Close the storage +func (s *Storage) Close() error { + return s.db.Close() +} + // GC deletes all expired entries func (s *Storage) gc() { tick := time.NewTicker(s.gcInterval)