001/* 002 * Copyright 2019 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.core.cache; 017 018/** 019 * CacheStats store hit, miss, and evictions of a cache. 020 * It can also compute rates, and compute the sum/difference between two CacheStats 021 */ 022public interface CacheStats 023{ 024 025 /** 026 * Returns the number of times cache lookup methods have returned either a cached or uncached value. 027 * This is defined as hitCount + missCount. 028 * @return the number of times cache lookup methods have returned either a cached or uncached value. 029 */ 030 public long requestCount(); 031 032 /** 033 * Returns the number of times cache lookup methods have returned a cached value. 034 * @return the number of times cache lookup methods have returned a cached value. 035 */ 036 public long hitCount(); 037 038 /** 039 * Returns the ratio of cache requests which were hits. This is defined as hitCount/requestCount. If requestCount equals 0, return 1 040 * @return the ratio of cache requests which were hits. 041 */ 042 public double hitRate(); 043 044 /** 045 * Returns the number of times cache lookup methods have returned an uncached (newly loaded) value, or null. 046 * @return missCount 047 */ 048 public long missCount(); 049 050 /** 051 * Returns the ratio of cache requests which were misses. This is defined as 052 * missCount/requestCount. If requestCount equals 0, return 0 053 * @return the ratio of cache requests which were misses. 054 */ 055 public double missRate(); 056 057 /** 058 * Returns the number of times an entry has been evicted. This count does not include manual invalidations. 059 * @return the number of times an entry has been evicted. 060 */ 061 public long evictionCount(); 062 063 /** 064 * Returns the ratio of cache requests that lead to an eviction. This is defined as 065 * evictionCount/requestCount. If requestCount equals 0, return 0 066 * @return the ratio of cache requests that lead to an eviction. 067 */ 068 public double evictionRate(); 069 070 /** 071 * Returns a new CacheStats representing the difference between this CacheStats and other. 072 * @param cacheStats the other CacheStats 073 * @return the CacheStats representing the difference between this CacheStats and other. 074 */ 075 public CacheStats minus(CacheStats cacheStats); 076 077 /** 078 * Returns a new CacheStats representing the sum between this CacheStats and other 079 * @param cacheStats the other CacheStats 080 * @return the new CacheStats representing the sum between this CacheStats and other. 081 */ 082 public CacheStats plus(CacheStats cacheStats); 083}