(cherry picked from commit 91fd0223a4)
Co-authored-by: George Robinson <george.robinson@grafana.com>
This commit is contained in:
co-authored by
George Robinson
parent
bb9d55cbd9
commit
7e89ef052a
@@ -11,9 +11,14 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultCacheTTL = 5 * time.Second
|
||||
)
|
||||
|
||||
func ProvideCacheService(cacheService *localcache.CacheService, sqlStore *sqlstore.SQLStore) *CacheServiceImpl {
|
||||
return &CacheServiceImpl{
|
||||
logger: log.New("datasources"),
|
||||
cacheTTL: DefaultCacheTTL,
|
||||
CacheService: cacheService,
|
||||
SQLStore: sqlStore,
|
||||
}
|
||||
@@ -21,6 +26,7 @@ func ProvideCacheService(cacheService *localcache.CacheService, sqlStore *sqlsto
|
||||
|
||||
type CacheServiceImpl struct {
|
||||
logger log.Logger
|
||||
cacheTTL time.Duration
|
||||
CacheService *localcache.CacheService
|
||||
SQLStore *sqlstore.SQLStore
|
||||
}
|
||||
@@ -55,7 +61,7 @@ func (dc *CacheServiceImpl) GetDatasource(
|
||||
if ds.Uid != "" {
|
||||
dc.CacheService.Set(uidKey(ds.OrgId, ds.Uid), ds, time.Second*5)
|
||||
}
|
||||
dc.CacheService.Set(cacheKey, ds, time.Second*5)
|
||||
dc.CacheService.Set(cacheKey, ds, dc.cacheTTL)
|
||||
return ds, nil
|
||||
}
|
||||
|
||||
@@ -91,8 +97,8 @@ func (dc *CacheServiceImpl) GetDatasourceByUID(
|
||||
|
||||
ds := query.Result
|
||||
|
||||
dc.CacheService.Set(uidCacheKey, ds, time.Second*5)
|
||||
dc.CacheService.Set(idKey(ds.Id), ds, time.Second*5)
|
||||
dc.CacheService.Set(uidCacheKey, ds, dc.cacheTTL)
|
||||
dc.CacheService.Set(idKey(ds.Id), ds, dc.cacheTTL)
|
||||
return ds, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user