| 99 | /// |
| 100 | /// - `value`: the value |
| 101 | public void put(Object key, Object value) { |
| 102 | if (cacheSize <= memoryCache.size()) { |
| 103 | // we need to find the oldest entry |
| 104 | Enumeration e = memoryCache.keys(); |
| 105 | long oldest = System.currentTimeMillis(); |
| 106 | Object oldestKey = null; |
| 107 | Object[] oldestValue = null; |
| 108 | while (e.hasMoreElements()) { |
| 109 | Object currentKey = e.nextElement(); |
| 110 | Object[] currentValue = (Object[]) memoryCache.get(currentKey); |
| 111 | long currentAge = ((Long) currentValue[0]).longValue(); |
| 112 | if (currentAge <= oldest || oldestValue == null) { |
| 113 | oldest = currentAge; |
| 114 | oldestKey = currentKey; |
| 115 | oldestValue = currentValue; |
| 116 | } |
| 117 | } |
| 118 | placeInStorageCache(oldestKey, oldest, oldestValue[1]); |
| 119 | weakCache.put(oldestKey, Display.getInstance().createSoftWeakRef(oldestValue[1])); |
| 120 | memoryCache.remove(oldestKey); |
| 121 | } |
| 122 | long lastAccess = System.currentTimeMillis(); |
| 123 | memoryCache.put(key, new Object[]{Long.valueOf(lastAccess), value}); |
| 124 | if (alwaysStore) { |
| 125 | placeInStorageCache(key, lastAccess, value); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | |
| 130 | /// Deletes a cached entry |