From c5bc723a6e93d9e55c5b856979237926a388054c Mon Sep 17 00:00:00 2001 From: Oleg Gaidarenko Date: Wed, 20 Mar 2019 11:36:28 +0100 Subject: [PATCH] Correct table names of sql storage for remotecache --- pkg/infra/remotecache/database_storage.go | 2 +- pkg/infra/remotecache/database_storage_test.go | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/pkg/infra/remotecache/database_storage.go b/pkg/infra/remotecache/database_storage.go index 1c39d74d800..16c42054df0 100644 --- a/pkg/infra/remotecache/database_storage.go +++ b/pkg/infra/remotecache/database_storage.go @@ -101,7 +101,7 @@ func (dc *databaseCache) Set(key string, value interface{}, expire time.Duration // insert or update depending on if item already exist if has { - sql := `UPDATE cache_data SET data=?, created=?, expire=? WHERE cache_key='?'` + sql := `UPDATE cache_data SET data=?, created_at=?, expires=? WHERE cache_key=?` _, err = session.Exec(sql, data, getTime().Unix(), expiresInSeconds, key) } else { sql := `INSERT INTO cache_data (cache_key,data,created_at,expires) VALUES(?,?,?,?)` diff --git a/pkg/infra/remotecache/database_storage_test.go b/pkg/infra/remotecache/database_storage_test.go index d15e26fd07f..455616ae664 100644 --- a/pkg/infra/remotecache/database_storage_test.go +++ b/pkg/infra/remotecache/database_storage_test.go @@ -5,7 +5,6 @@ import ( "time" "github.com/bmizerany/assert" - "github.com/grafana/grafana/pkg/log" "github.com/grafana/grafana/pkg/services/sqlstore" ) @@ -54,3 +53,20 @@ func TestDatabaseStorageGarbageCollection(t *testing.T) { _, err = db.Get("key5") assert.Equal(t, err, nil) } + +func TestSecondSet(t *testing.T) { + var err error + sqlstore := sqlstore.InitTestDB(t) + + db := &databaseCache{ + SQLStore: sqlstore, + log: log.New("remotecache.database"), + } + + obj := &CacheableStruct{String: "hey!"} + + err = db.Set("killa-gorilla", obj, 0) + err = db.Set("killa-gorilla", obj, 0) + + assert.Equal(t, err, nil) +}