settings: Instanciate only a single instance of the ServiceHandler/Store

Share the same instance between the HTTP and the GRPC service. This is
in preparation for moving the cache of the metadata storage backend to a
go-micro/store based implementation. By sharing the same service instance in
the HTTP and GRPC services we can avoid the usage of global variables for the
caches, which will make the move to the go-micro/store implementation simpler.
This commit is contained in:
Ralf Haferkamp
2023-05-09 14:30:35 +02:00
committed by Ralf Haferkamp
parent 3e92e409f7
commit 18bb3dbaca
6 changed files with 46 additions and 22 deletions
@@ -11,10 +11,6 @@ import (
var (
cachettl = 0
// these need to be global instances for now as the `Service` (and therefore the `Store`) are instantiated twice (for grpc and http)
// therefore caches need to cover both instances
dircache = initCache(cachettl)
filescache = initCache(cachettl)
)
// CachedMDC is cache for the metadataclient
@@ -99,8 +95,8 @@ func (c *CachedMDC) MakeDirIfNotExist(ctx context.Context, id string) error {
// Init instantiates the caches
func (c *CachedMDC) Init(ctx context.Context, id string) error {
c.dirs = dircache
c.files = filescache
c.dirs = initCache(cachettl)
c.files = initCache(cachettl)
return c.next.Init(ctx, id)
}