use constants for cache type

This commit is contained in:
bergquist 2019-03-14 09:27:41 +01:00
parent 0a86a1d7b6
commit 6d42d43b22
6 changed files with 11 additions and 5 deletions

View File

@ -10,6 +10,8 @@ import (
var getTime = time.Now
const databaseCacheType = "database"
type databaseCache struct {
SQLStore *sqlstore.SqlStore
log log.Logger

View File

@ -7,6 +7,8 @@ import (
"github.com/grafana/grafana/pkg/setting"
)
const memcachedCacheType = "memcached"
type memcachedStorage struct {
c *memcache.Client
}

View File

@ -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)
}

View File

@ -7,6 +7,8 @@ import (
redis "gopkg.in/redis.v2"
)
const redisCacheType = "redis"
type redisStorage struct {
c *redis.Client
}

View File

@ -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)
}

View File

@ -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
}