summaryrefslogtreecommitdiffstats
path: root/store/local_cache_supplier.go
diff options
context:
space:
mode:
Diffstat (limited to 'store/local_cache_supplier.go')
-rw-r--r--store/local_cache_supplier.go36
1 files changed, 19 insertions, 17 deletions
diff --git a/store/local_cache_supplier.go b/store/local_cache_supplier.go
index a2f03db8e..91aa94768 100644
--- a/store/local_cache_supplier.go
+++ b/store/local_cache_supplier.go
@@ -21,11 +21,15 @@ const (
type LocalCacheSupplier struct {
next LayeredStoreSupplier
reactionCache *utils.Cache
+ metrics einterfaces.MetricsInterface
+ cluster einterfaces.ClusterInterface
}
-func NewLocalCacheSupplier() *LocalCacheSupplier {
+func NewLocalCacheSupplier(metrics einterfaces.MetricsInterface, cluster einterfaces.ClusterInterface) *LocalCacheSupplier {
supplier := &LocalCacheSupplier{
reactionCache: utils.NewLruWithParams(REACTION_CACHE_SIZE, "Reaction", REACTION_CACHE_SEC, model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_REACTIONS),
+ metrics: metrics,
+ cluster: cluster,
}
registerClusterHandlers(supplier)
@@ -47,58 +51,56 @@ func (s *LocalCacheSupplier) Next() LayeredStoreSupplier {
return s.next
}
-func doStandardReadCache(ctx context.Context, cache utils.ObjectCache, key string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
- metrics := einterfaces.GetMetricsInterface()
-
+func (s *LocalCacheSupplier) doStandardReadCache(ctx context.Context, cache utils.ObjectCache, key string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
if hintsContains(hints, LSH_NO_CACHE) {
- if metrics != nil {
- metrics.IncrementMemCacheMissCounter(cache.Name())
+ if s.metrics != nil {
+ s.metrics.IncrementMemCacheMissCounter(cache.Name())
}
return nil
}
if cacheItem, ok := cache.Get(key); ok {
- if metrics != nil {
- metrics.IncrementMemCacheHitCounter(cache.Name())
+ if s.metrics != nil {
+ s.metrics.IncrementMemCacheHitCounter(cache.Name())
}
result := NewSupplierResult()
result.Data = cacheItem
return result
}
- if metrics != nil {
- metrics.IncrementMemCacheMissCounter(cache.Name())
+ if s.metrics != nil {
+ s.metrics.IncrementMemCacheMissCounter(cache.Name())
}
return nil
}
-func doStandardAddToCache(ctx context.Context, cache utils.ObjectCache, key string, result *LayeredStoreSupplierResult, hints ...LayeredStoreHint) {
+func (s *LocalCacheSupplier) doStandardAddToCache(ctx context.Context, cache utils.ObjectCache, key string, result *LayeredStoreSupplierResult, hints ...LayeredStoreHint) {
if result.Err == nil && result.Data != nil {
cache.AddWithDefaultExpires(key, result.Data)
}
}
-func doInvalidateCacheCluster(cache utils.ObjectCache, key string) {
+func (s *LocalCacheSupplier) doInvalidateCacheCluster(cache utils.ObjectCache, key string) {
cache.Remove(key)
- if einterfaces.GetClusterInterface() != nil {
+ if s.cluster != nil {
msg := &model.ClusterMessage{
Event: cache.GetInvalidateClusterEvent(),
SendType: model.CLUSTER_SEND_BEST_EFFORT,
Data: key,
}
- einterfaces.GetClusterInterface().SendClusterMessage(msg)
+ s.cluster.SendClusterMessage(msg)
}
}
-func doClearCacheCluster(cache utils.ObjectCache) {
+func (s *LocalCacheSupplier) doClearCacheCluster(cache utils.ObjectCache) {
cache.Purge()
- if einterfaces.GetClusterInterface() != nil {
+ if s.cluster != nil {
msg := &model.ClusterMessage{
Event: cache.GetInvalidateClusterEvent(),
SendType: model.CLUSTER_SEND_BEST_EFFORT,
Data: CLEAR_CACHE_MESSAGE_DATA,
}
- einterfaces.GetClusterInterface().SendClusterMessage(msg)
+ s.cluster.SendClusterMessage(msg)
}
}