Module bus.cache

Interface Metrics

All Known Implementing Classes:
AbstractMetrics, H2Metrics, MemoryMetrics, MySQLMetrics, PostgreSQLMetrics, SqliteMetrics, ZookeeperMetrics

public interface Metrics
缓存命中统计接口

定义缓存命中率统计的核心操作,包括记录请求次数、命中次数、获取统计信息和重置统计。 提供对缓存模式或分组的命中率统计功能,适用于监控缓存性能。

Since:
Java 17+
Author:
Kimi Liu
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
    缓存命中率数据对象
  • Method Summary

    Modifier and Type
    Method
    Description
    获取缓存命中率统计信息
    void
    hitIncr(String pattern, int count)
    增加缓存命中次数
    void
    reqIncr(String pattern, int count)
    增加缓存请求次数
    void
    reset(String pattern)
    重置指定缓存模式的命中率统计
    void
    重置所有缓存模式的命中率统计
    default String
    获取汇总名称
  • Method Details

    • reqIncr

      void reqIncr(String pattern, int count)
      增加缓存请求次数

      为指定缓存模式或分组增加请求次数,用于统计缓存访问频率。 示例代码:

      
       Metrics metrics = new SomeMetricsImpl();
       metrics.reqIncr("userCache", 1);
       
      Parameters:
      pattern - 缓存模式或分组名称
      count - 增加的请求数量
    • hitIncr

      void hitIncr(String pattern, int count)
      增加缓存命中次数

      为指定缓存模式或分组增加命中次数,用于统计缓存命中情况。 示例代码:

      
       Metrics metrics = new SomeMetricsImpl();
       metrics.hitIncr("userCache", 1);
       
      Parameters:
      pattern - 缓存模式或分组名称
      count - 增加的命中数量
    • getHitting

      Map<String,Metrics.Snapshot> getHitting()
      获取缓存命中率统计信息

      返回缓存命中率统计数据,键为缓存模式或分组名称,值为对应的命中率数据对象。 示例代码:

      
       Metrics metrics = new SomeMetricsImpl();
       Map<String, Snapshot> stats = metrics.getHitting();
       stats.forEach((pattern, snapshot) -> System.out.println(pattern + ": 命中率 " + snapshot.getRate()));
       
      Returns:
      包含缓存模式及其命中率数据的映射
    • reset

      void reset(String pattern)
      重置指定缓存模式的命中率统计

      清空指定缓存模式或分组的命中率统计数据,重新开始计数。 示例代码:

      
       Metrics metrics = new SomeMetricsImpl();
       metrics.reset("userCache");
       
      Parameters:
      pattern - 缓存模式或分组名称
    • resetAll

      void resetAll()
      重置所有缓存模式的命中率统计

      清空所有缓存模式或分组的命中率统计数据,重新开始计数。 示例代码:

      
       Metrics metrics = new SomeMetricsImpl();
       metrics.resetAll();
       
    • summaryName

      default String summaryName()
      获取汇总名称

      根据系统语言环境返回汇总名称,中文环境返回“全局”,其他环境返回“summary”。 示例代码:

      
       Metrics metrics = new SomeMetricsImpl();
       String summary = metrics.summaryName();
       System.out.println("汇总名称: " + summary);
       
      Returns:
      汇总名称