1 64 65 package com.jcorporate.expresso.core.cache; 66 67 76 public final class CacheEntry { 77 78 81 private Cacheable contents = null; 82 83 86 protected long created = 0; 87 88 91 private long expires = -1; 92 private long useCount = 0; 93 94 100 public CacheEntry(Cacheable newContents) { 101 contents = newContents; 102 expires = -1; 103 created = System.currentTimeMillis(); 104 } 105 106 113 public CacheEntry(Cacheable newContents, long newExpires) { 114 contents = newContents; 115 if (newExpires <= 0) { 116 expires = -1; 117 } else { 118 expires = System.currentTimeMillis() + newExpires; 119 } 120 created = System.currentTimeMillis(); 121 } 122 123 126 public void clearUsedCount() { 127 useCount = 0; 128 } 129 130 133 public Cacheable getContents() { 134 return contents; 135 } 136 137 140 public long getCreated() { 141 return created; 142 } 143 144 147 public long getExpires() { 148 return expires; 149 } 150 151 154 public String getKey() { 155 return contents.getKey(); 156 } 157 158 163 public long getUsedCount() { 164 return useCount; 165 } 166 167 170 public void incrementUsedCount() { 171 useCount++; 172 } 173 174 179 public void setExpiration(long expiration) { 180 if (expiration < 0) { 181 expires = -1; 182 } else { 183 expires = System.currentTimeMillis() + expiration; 184 } 185 } 186 187 193 public final boolean isExpired() { 194 return (expires > 0 && (System.currentTimeMillis() > expires)) ? true : false; 195 } 196 197 } 198 199 | Popular Tags |