spring-data-redis DefaultCacheStatisticsCollector 源码

  • 2022-08-16
  • 浏览 (727)

spring-data-redis DefaultCacheStatisticsCollector 代码

文件路径:/src/main/java/org/springframework/data/redis/cache/DefaultCacheStatisticsCollector.java

/*
 * Copyright 2020-2022 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.data.redis.cache;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Default {@link CacheStatisticsCollector} implementation holding synchronized per cache
 * {@link MutableCacheStatistics}.
 *
 * @author Christoph Strobl
 * @since 2.4
 */
class DefaultCacheStatisticsCollector implements CacheStatisticsCollector {

	private final Map<String, MutableCacheStatistics> stats = new ConcurrentHashMap<>();

	@Override
	public void incPuts(String cacheName) {
		statsFor(cacheName).incPuts();
	}

	@Override
	public void incGets(String cacheName) {
		statsFor(cacheName).incGets();
	}

	@Override
	public void incHits(String cacheName) {
		statsFor(cacheName).incHits();
	}

	@Override
	public void incMisses(String cacheName) {
		statsFor(cacheName).incMisses();
	}

	@Override
	public void incDeletesBy(String cacheName, int value) {
		statsFor(cacheName).incDeletes(value);
	}

	@Override
	public void incLockTime(String name, long durationNS) {
		statsFor(name).incLockWaitTime(durationNS);
	}

	@Override
	public void reset(String cacheName) {
		statsFor(cacheName).reset();
	}

	@Override
	public CacheStatistics getCacheStatistics(String cacheName) {
		return statsFor(cacheName).captureSnapshot();
	}

	private MutableCacheStatistics statsFor(String cacheName) {
		return stats.computeIfAbsent(cacheName, MutableCacheStatistics::new);
	}
}

相关信息

spring-data-redis 源码目录

相关文章

spring-data-redis BatchStrategies 源码

spring-data-redis BatchStrategy 源码

spring-data-redis CacheKeyPrefix 源码

spring-data-redis CacheStatistics 源码

spring-data-redis CacheStatisticsCollector 源码

spring-data-redis CacheStatisticsProvider 源码

spring-data-redis DefaultRedisCacheWriter 源码

spring-data-redis MutableCacheStatistics 源码

spring-data-redis NoOpCacheStatisticsCollector 源码

spring-data-redis RedisCache 源码

0  赞