MM-57193: Standardize the cache names (#26441)

We use the same name for hit/miss/invalidation metrics.

The downside is that now we have conflated a full cache purge
and a single cache key invalidation into a single label, but
the advantage is that it's easier to monitor the usage of a single
cache.

And moreover, duplicating the same string across multiple places
increases the chances of making a mistake. Centralizing the cache
name only at instantiation simplifies the code.

After this, we would be ready to use Redis.

https://mattermost.atlassian.net/browse/MM-57193

```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2024-03-19 09:59:00 +05:30
коммит произвёл GitHub
родитель 53471c7e8c
Коммит 7679f51e3e
9 изменённых файлов: 24 добавлений и 35 удалений

Просмотреть файл

@@ -275,6 +275,7 @@ func New(sc ServiceConfig, options ...Option) (*PlatformService, error) {
// Needed before loading license
ps.statusCache, err = ps.cacheProvider.NewCache(&cache.CacheOptions{
Name: "Status",
Size: model.StatusCacheSize,
Striped: true,
StripedBuckets: maxInt(runtime.NumCPU()-1, 1),

Просмотреть файл

@@ -65,12 +65,12 @@ func (ps *PlatformService) GetStatusesByIds(userIDs []string) (map[string]any, *
if err := ps.statusCache.Get(userID, &status); err == nil {
statusMap[userID] = status.Status
if metrics != nil {
metrics.IncrementMemCacheHitCounter("Status")
metrics.IncrementMemCacheHitCounter(ps.statusCache.Name())
}
} else {
missingUserIds = append(missingUserIds, userID)
if metrics != nil {
metrics.IncrementMemCacheMissCounter("Status")
metrics.IncrementMemCacheMissCounter(ps.statusCache.Name())
}
}
}
@@ -112,12 +112,12 @@ func (ps *PlatformService) GetUserStatusesByIds(userIDs []string) ([]*model.Stat
if err := ps.statusCache.Get(userID, &status); err == nil {
statusMap = append(statusMap, status)
if metrics != nil {
metrics.IncrementMemCacheHitCounter("Status")
metrics.IncrementMemCacheHitCounter(ps.statusCache.Name())
}
} else {
missingUserIds = append(missingUserIds, userID)
if metrics != nil {
metrics.IncrementMemCacheMissCounter("Status")
metrics.IncrementMemCacheMissCounter(ps.statusCache.Name())
}
}
}