001package com.avaje.ebean.cache; 002 003/** 004 * The statistics collected per cache. 005 * <p> 006 * These can be monitored to review the effectiveness of a particular cache. 007 * </p> 008 * <p> 009 * Depending on the cache implementation not all the statistics may be collected. 010 * </p> 011 */ 012public class ServerCacheStatistics { 013 014 protected String cacheName; 015 016 protected int maxSize; 017 018 protected int size; 019 020 protected long hitCount; 021 022 protected long missCount; 023 024 protected long insertCount; 025 026 protected long updateCount; 027 028 protected long removeCount; 029 030 protected long clearCount; 031 032 protected long evictionRunCount; 033 034 protected long evictionRunMicros; 035 036 protected long evictByIdle; 037 038 protected long evictByTTL; 039 040 protected long evictByLRU; 041 042 public String toString() { 043 //noinspection StringBufferReplaceableByString 044 StringBuilder sb = new StringBuilder(80); 045 sb.append(cacheName); 046 sb.append(" maxSize:").append(maxSize); 047 sb.append(" size:").append(size); 048 sb.append(" hitRatio:").append(getHitRatio()); 049 sb.append(" hit:").append(hitCount); 050 sb.append(" miss:").append(missCount); 051 sb.append(" insert:").append(insertCount); 052 sb.append(" update:").append(updateCount); 053 sb.append(" remove:").append(removeCount); 054 sb.append(" clear:").append(clearCount); 055 sb.append(" evictByIdle:").append(evictByIdle); 056 sb.append(" evictByTTL:").append(evictByTTL); 057 sb.append(" evictByLRU:").append(evictByLRU); 058 sb.append(" evictionRunCount:").append(evictionRunCount); 059 sb.append(" evictionRunMicros:").append(evictionRunMicros); 060 return sb.toString(); 061 } 062 063 /** 064 * Returns an int from 0 to 100 (percentage) for the hit ratio. 065 * <p> 066 * A hit ratio of 100 means every get request against the cache hits an entry. 067 * </p> 068 */ 069 public int getHitRatio() { 070 long totalCount = hitCount + missCount; 071 if (totalCount == 0) { 072 return 0; 073 } else { 074 return (int)(hitCount * 100 / totalCount); 075 } 076 } 077 078 /** 079 * Return the name of the cache. 080 */ 081 public String getCacheName() { 082 return cacheName; 083 } 084 085 /** 086 * Set the name of the cache. 087 */ 088 public void setCacheName(String cacheName) { 089 this.cacheName = cacheName; 090 } 091 092 /** 093 * Return the hit count. The number of successful gets. 094 */ 095 public long getHitCount() { 096 return hitCount; 097 } 098 099 /** 100 * Set the hit count. 101 */ 102 public void setHitCount(long hitCount) { 103 this.hitCount = hitCount; 104 } 105 106 /** 107 * Return the miss count. The number of gets that returned null. 108 */ 109 public long getMissCount() { 110 return missCount; 111 } 112 113 /** 114 * Set the miss count. 115 */ 116 public void setMissCount(long missCount) { 117 this.missCount = missCount; 118 } 119 120 /** 121 * Return the size of the cache. 122 */ 123 public int getSize() { 124 return size; 125 } 126 127 /** 128 * Set the size of the cache. 129 */ 130 public void setSize(int size) { 131 this.size = size; 132 } 133 134 /** 135 * Return the maximum size of the cache. 136 * <p> 137 * Can be used in conjunction with the size to determine if the cache use is 138 * being potentially limited by its maximum size. 139 * </p> 140 */ 141 public int getMaxSize() { 142 return maxSize; 143 } 144 145 /** 146 * Set the maximum size of the cache. 147 */ 148 public void setMaxSize(int maxSize) { 149 this.maxSize = maxSize; 150 } 151 152 /** 153 * Set the put insert count. 154 */ 155 public void setInsertCount(long insertCount) { 156 this.insertCount = insertCount; 157 } 158 159 /** 160 * Return the put insert count. 161 */ 162 public long getInsertCount() { 163 return insertCount; 164 } 165 166 /** 167 * Set the put update count. 168 */ 169 public void setUpdateCount(long updateCount) { 170 this.updateCount = updateCount; 171 } 172 173 /** 174 * Return the put update count. 175 */ 176 public long getUpdateCount() { 177 return updateCount; 178 } 179 180 /** 181 * Set the remove count. 182 */ 183 public void setRemoveCount(long removeCount) { 184 this.removeCount = removeCount; 185 } 186 187 /** 188 * Return the remove count. 189 */ 190 public long getRemoveCount() { 191 return removeCount; 192 } 193 194 /** 195 * Set the clear count. 196 */ 197 public void setClearCount(long clearCount) { 198 this.clearCount = clearCount; 199 } 200 201 /** 202 * Return the clear count. 203 */ 204 public long getClearCount() { 205 return clearCount; 206 } 207 208 /** 209 * Set the eviction run count. 210 */ 211 public void setEvictionRunCount(long evictCount) { 212 this.evictionRunCount = evictCount; 213 } 214 215 /** 216 * Return the eviction run count. 217 */ 218 public long getEvictionRunCount() { 219 return evictionRunCount; 220 } 221 222 /** 223 * Set the eviction run time in micros. 224 */ 225 public void setEvictionRunMicros(long evictionRunMicros) { 226 this.evictionRunMicros = evictionRunMicros; 227 } 228 229 /** 230 * Return the eviction run time in micros. 231 */ 232 public long getEvictionRunMicros() { 233 return evictionRunMicros; 234 } 235 236 /** 237 * Set the count of entries evicted due to idle time. 238 */ 239 public void setEvictByIdle(long evictByIdle) { 240 this.evictByIdle = evictByIdle; 241 } 242 243 /** 244 * Return the count of entries evicted due to idle time. 245 */ 246 public long getEvictByIdle() { 247 return evictByIdle; 248 } 249 250 /** 251 * Set the count of entries evicted due to time to live. 252 */ 253 public void setEvictByTTL(long evictByTTL) { 254 this.evictByTTL = evictByTTL; 255 } 256 257 /** 258 * Return the count of entries evicted due to time to live. 259 */ 260 public long getEvictByTTL() { 261 return evictByTTL; 262 } 263 264 /** 265 * Set the count of entries evicted due to time least recently used. 266 */ 267 public void setEvictByLRU(long evictByLRU) { 268 this.evictByLRU = evictByLRU; 269 } 270 271 /** 272 * Return the count of entries evicted due to time least recently used. 273 */ 274 public long getEvictByLRU() { 275 return evictByLRU; 276 } 277}