1 20 package org.enhydra.dods.cache.lru; 21 22 import org.enhydra.dods.cache.base.DODSCache; 23 24 35 public class DODSLRUCache extends LRUCache implements DODSCache { 36 37 40 protected int cacheAccessNum = 0; 41 42 45 protected int cacheHitsNum = 0; 46 47 52 DODSLRUCache(int maxSize) { 53 super(maxSize); 54 clearStatistics(); 55 } 56 57 62 public int getCacheAccessNum() { 63 return cacheAccessNum; 64 } 65 66 71 public void setCacheAccessNum(int num) { 72 this.cacheAccessNum = num; 73 } 74 75 78 public void incrementCacheAccessNum(int num) { 79 cacheAccessNum += num; 80 } 81 82 87 public int getCacheHitsNum() { 88 return cacheHitsNum; 89 } 90 91 96 public void setCacheHitsNum(int cacheHitsNum) { 97 this.cacheHitsNum = cacheHitsNum; 98 } 99 100 103 public void incrementCacheHitsNum(int num) { 104 cacheHitsNum += num; 105 } 106 107 113 public double getUsedPercents() { 114 int maxCacheSize = this.maxEntries; 115 116 if (maxCacheSize == 0) { 117 return 0; 118 } 119 if (maxCacheSize < 0) { 120 return 100; 121 } 122 int temp = size() * 10000; 123 double res = temp / maxCacheSize; 124 125 return res / 100; 126 } 127 128 135 public double getCacheHitsPercents() { 136 if (cacheAccessNum == 0) { 137 return 0; 138 } 139 int temp = cacheHitsNum * 10000; 140 double res = temp / cacheAccessNum; 141 142 return res / 100; 143 } 144 145 148 public void clearStatistics() { 149 this.cacheAccessNum = 0; 150 this.cacheHitsNum = 0; 151 } 152 153 public boolean isNeedToSynchronize() { 154 return true; 155 } 156 157 } 158 | Popular Tags |