Selaa lähdekoodia

use constants for cache type

bergquist 6 vuotta sitten
vanhempi
commit
6d42d43b22

+ 2 - 0
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

+ 2 - 0
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
 }

+ 1 - 1
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)
 }

+ 2 - 0
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
 }

+ 1 - 1
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)
 }

+ 3 - 3
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
 	}