Module bus.cache

Class MemoryMetrics

java.lang.Object
org.miaixz.bus.cache.support.metrics.MemoryMetrics
All Implemented Interfaces:
Metrics

public class MemoryMetrics extends Object implements Metrics
内存缓存命中率统计实现

基于内存的缓存命中率统计实现,使用ConcurrentHashMap存储命中次数和请求次数, 支持并发更新,适用于单机环境或测试环境。

Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • MemoryMetrics

      public MemoryMetrics()
  • Method Details

    • hitIncr

      public void hitIncr(String pattern, int count)
      增加命中次数
      Specified by:
      hitIncr in interface Metrics
      Parameters:
      pattern - 缓存模式/分组名称
      count - 增加的命中数量
    • reqIncr

      public void reqIncr(String pattern, int count)
      增加请求次数
      Specified by:
      reqIncr in interface Metrics
      Parameters:
      pattern - 缓存模式/分组名称
      count - 增加的请求数量
    • getHitting

      public Map<String,Metrics.Snapshot> getHitting()
      获取缓存命中率统计信息
      Specified by:
      getHitting in interface Metrics
      Returns:
      缓存命中率统计映射,键为缓存模式/分组名称,值为HittingDO对象
    • reset

      public void reset(String pattern)
      重置指定缓存模式的命中率统计
      Specified by:
      reset in interface Metrics
      Parameters:
      pattern - 缓存模式/分组名称
    • resetAll

      public void resetAll()
      重置所有缓存模式的命中率统计
      Specified by:
      resetAll in interface Metrics