From 6d42d43b2251fb2147ce285e924450daef4ae2d4 Mon Sep 17 00:00:00 2001 From: bergquist Date: Thu, 14 Mar 2019 09:27:41 +0100 Subject: [PATCH] use constants for cache type --- pkg/infra/remotecache/database_storage.go | 2 ++ pkg/infra/remotecache/memcached_storage.go | 2 ++ pkg/infra/remotecache/memcached_storage_integration_test.go | 2 +- pkg/infra/remotecache/redis_storage.go | 2 ++ pkg/infra/remotecache/redis_storage_integration_test.go | 2 +- pkg/infra/remotecache/remotecache.go | 6 +++--- 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/infra/remotecache/database_storage.go b/pkg/infra/remotecache/database_storage.go index e188f25f76b..1c39d74d800 100644 --- a/pkg/infra/remotecache/database_storage.go +++ b/pkg/infra/remotecache/database_storage.go @@ -10,6 +10,8 @@ import ( var getTime = time.Now +const databaseCacheType = "database" + type databaseCache struct { SQLStore *sqlstore.SqlStore log log.Logger diff --git a/pkg/infra/remotecache/memcached_storage.go b/pkg/infra/remotecache/memcached_storage.go index 1947d4ce56d..5424a05ad02 100644 --- a/pkg/infra/remotecache/memcached_storage.go +++ b/pkg/infra/remotecache/memcached_storage.go @@ -7,6 +7,8 @@ import ( "github.com/grafana/grafana/pkg/setting" ) +const memcachedCacheType = "memcached" + type memcachedStorage struct { c *memcache.Client } diff --git a/pkg/infra/remotecache/memcached_storage_integration_test.go b/pkg/infra/remotecache/memcached_storage_integration_test.go index de7692e25d5..d1d82468644 100644 --- a/pkg/infra/remotecache/memcached_storage_integration_test.go +++ b/pkg/infra/remotecache/memcached_storage_integration_test.go @@ -9,7 +9,7 @@ import ( ) func TestMemcachedCacheStorage(t *testing.T) { - opts := &setting.RemoteCacheOptions{Name: "memcached", ConnStr: "localhost:11211"} + opts := &setting.RemoteCacheOptions{Name: memcachedCacheType, ConnStr: "localhost:11211"} client := createTestClient(t, opts, nil) runTestsForClient(t, client) } diff --git a/pkg/infra/remotecache/redis_storage.go b/pkg/infra/remotecache/redis_storage.go index c3ea2354d73..bd54b843119 100644 --- a/pkg/infra/remotecache/redis_storage.go +++ b/pkg/infra/remotecache/redis_storage.go @@ -7,6 +7,8 @@ import ( redis "gopkg.in/redis.v2" ) +const redisCacheType = "redis" + type redisStorage struct { c *redis.Client } diff --git a/pkg/infra/remotecache/redis_storage_integration_test.go b/pkg/infra/remotecache/redis_storage_integration_test.go index 0a63fbe31ec..8d54fc9ff14 100644 --- a/pkg/infra/remotecache/redis_storage_integration_test.go +++ b/pkg/infra/remotecache/redis_storage_integration_test.go @@ -10,7 +10,7 @@ import ( func TestRedisCacheStorage(t *testing.T) { - opts := &setting.RemoteCacheOptions{Name: "redis", ConnStr: "localhost:6379"} + opts := &setting.RemoteCacheOptions{Name: redisCacheType, ConnStr: "localhost:6379"} client := createTestClient(t, opts, nil) runTestsForClient(t, client) } diff --git a/pkg/infra/remotecache/remotecache.go b/pkg/infra/remotecache/remotecache.go index 25dbedcaff3..9219fa33a08 100644 --- a/pkg/infra/remotecache/remotecache.go +++ b/pkg/infra/remotecache/remotecache.go @@ -92,15 +92,15 @@ func (ds *RemoteCache) Run(ctx context.Context) error { } func createClient(opts *setting.RemoteCacheOptions, sqlstore *sqlstore.SqlStore) (CacheStorage, error) { - if opts.Name == "redis" { + if opts.Name == redisCacheType { return newRedisStorage(opts), nil } - if opts.Name == "memcached" { + if opts.Name == memcachedCacheType { return newMemcachedStorage(opts), nil } - if opts.Name == "database" { + if opts.Name == databaseCacheType { return newDatabaseCache(sqlstore), nil }