mirror of
https://github.com/grafana/grafana.git
synced 2024-11-22 17:06:57 -06:00
use constants for cache type
This commit is contained in:
parent
0a86a1d7b6
commit
6d42d43b22
@ -10,6 +10,8 @@ import (
|
||||
|
||||
var getTime = time.Now
|
||||
|
||||
const databaseCacheType = "database"
|
||||
|
||||
type databaseCache struct {
|
||||
SQLStore *sqlstore.SqlStore
|
||||
log log.Logger
|
||||
|
@ -7,6 +7,8 @@ import (
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
const memcachedCacheType = "memcached"
|
||||
|
||||
type memcachedStorage struct {
|
||||
c *memcache.Client
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ import (
|
||||
redis "gopkg.in/redis.v2"
|
||||
)
|
||||
|
||||
const redisCacheType = "redis"
|
||||
|
||||
type redisStorage struct {
|
||||
c *redis.Client
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user