From 6809d2bb292e57efb685e1a676ed0d2b9a3635ab Mon Sep 17 00:00:00 2001 From: Carl Bergquist Date: Thu, 13 Jun 2019 10:55:38 +0200 Subject: [PATCH] codestyle: moves cache to infra (#17519) --- pkg/api/http_server.go | 4 ++-- pkg/cmd/grafana-server/server.go | 2 +- pkg/{services/cache => infra/localcache}/cache.go | 4 +++- pkg/services/datasources/cache.go | 6 +++--- pkg/services/sqlstore/sqlstore.go | 10 +++++----- 5 files changed, 14 insertions(+), 12 deletions(-) rename pkg/{services/cache => infra/localcache}/cache.go (69%) diff --git a/pkg/api/http_server.go b/pkg/api/http_server.go index 926a687c791..1832e29ed85 100644 --- a/pkg/api/http_server.go +++ b/pkg/api/http_server.go @@ -16,13 +16,13 @@ import ( httpstatic "github.com/grafana/grafana/pkg/api/static" "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/components/simplejson" + "github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/remotecache" "github.com/grafana/grafana/pkg/middleware" "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/plugins" "github.com/grafana/grafana/pkg/registry" - "github.com/grafana/grafana/pkg/services/cache" "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/hooks" "github.com/grafana/grafana/pkg/services/quota" @@ -60,7 +60,7 @@ type HTTPServer struct { RenderService rendering.Service `inject:""` Cfg *setting.Cfg `inject:""` HooksService *hooks.HooksService `inject:""` - CacheService *cache.CacheService `inject:""` + CacheService *localcache.CacheService `inject:""` DatasourceCache datasources.CacheService `inject:""` AuthTokenService models.UserTokenService `inject:""` QuotaService *quota.QuotaService `inject:""` diff --git a/pkg/cmd/grafana-server/server.go b/pkg/cmd/grafana-server/server.go index f1823260e16..c1cf07bfee2 100644 --- a/pkg/cmd/grafana-server/server.go +++ b/pkg/cmd/grafana-server/server.go @@ -12,6 +12,7 @@ import ( "time" "github.com/facebookgo/inject" + "github.com/patrickmn/go-cache" "golang.org/x/sync/errgroup" "github.com/grafana/grafana/pkg/api" @@ -31,7 +32,6 @@ import ( "github.com/grafana/grafana/pkg/registry" _ "github.com/grafana/grafana/pkg/services/alerting" _ "github.com/grafana/grafana/pkg/services/auth" - "github.com/grafana/grafana/pkg/services/cache" _ "github.com/grafana/grafana/pkg/services/cleanup" _ "github.com/grafana/grafana/pkg/services/notifications" _ "github.com/grafana/grafana/pkg/services/provisioning" diff --git a/pkg/services/cache/cache.go b/pkg/infra/localcache/cache.go similarity index 69% rename from pkg/services/cache/cache.go rename to pkg/infra/localcache/cache.go index 93b2cf76e26..f1d465405e8 100644 --- a/pkg/services/cache/cache.go +++ b/pkg/infra/localcache/cache.go @@ -1,4 +1,4 @@ -package cache +package localcache import ( "time" @@ -6,10 +6,12 @@ import ( gocache "github.com/patrickmn/go-cache" ) +// CacheService cache any object in memory on the local instance. type CacheService struct { *gocache.Cache } +// New returns a new CacheService func New(defaultExpiration, cleanupInterval time.Duration) *CacheService { return &CacheService{ Cache: gocache.New(defaultExpiration, cleanupInterval), diff --git a/pkg/services/datasources/cache.go b/pkg/services/datasources/cache.go index 0cd2bae63b5..94dc2f9d064 100644 --- a/pkg/services/datasources/cache.go +++ b/pkg/services/datasources/cache.go @@ -5,9 +5,9 @@ import ( "time" "github.com/grafana/grafana/pkg/bus" + "github.com/grafana/grafana/pkg/infra/localcache" m "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/registry" - "github.com/grafana/grafana/pkg/services/cache" ) type CacheService interface { @@ -15,8 +15,8 @@ type CacheService interface { } type CacheServiceImpl struct { - Bus bus.Bus `inject:""` - CacheService *cache.CacheService `inject:""` + Bus bus.Bus `inject:""` + CacheService *localcache.CacheService `inject:""` } func init() { diff --git a/pkg/services/sqlstore/sqlstore.go b/pkg/services/sqlstore/sqlstore.go index 675af5f02bb..46d5fb5ec35 100644 --- a/pkg/services/sqlstore/sqlstore.go +++ b/pkg/services/sqlstore/sqlstore.go @@ -13,11 +13,11 @@ import ( "github.com/go-sql-driver/mysql" "github.com/go-xorm/xorm" "github.com/grafana/grafana/pkg/bus" + "github.com/grafana/grafana/pkg/infra/localcache" "github.com/grafana/grafana/pkg/infra/log" m "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/registry" "github.com/grafana/grafana/pkg/services/annotations" - "github.com/grafana/grafana/pkg/services/cache" "github.com/grafana/grafana/pkg/services/sqlstore/migrations" "github.com/grafana/grafana/pkg/services/sqlstore/migrator" "github.com/grafana/grafana/pkg/services/sqlstore/sqlutil" @@ -50,9 +50,9 @@ func init() { } type SqlStore struct { - Cfg *setting.Cfg `inject:""` - Bus bus.Bus `inject:""` - CacheService *cache.CacheService `inject:""` + Cfg *setting.Cfg `inject:""` + Bus bus.Bus `inject:""` + CacheService *localcache.CacheService `inject:""` dbCfg DatabaseConfig engine *xorm.Engine @@ -296,7 +296,7 @@ func InitTestDB(t ITestDB) *SqlStore { sqlstore := &SqlStore{} sqlstore.skipEnsureAdmin = true sqlstore.Bus = bus.New() - sqlstore.CacheService = cache.New(5*time.Minute, 10*time.Minute) + sqlstore.CacheService = localcache.New(5*time.Minute, 10*time.Minute) dbType := migrator.SQLITE