MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / put

Method put

CodenameOne/src/com/codename1/io/CacheMap.java:101–127  ·  view source on GitHub ↗
(Object key, Object value)

Source from the content-addressed store, hash-verified

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

Callers 15

getMethod · 0.95
putAndGetMethod · 0.95
putMultipleItemsMethod · 0.95
deleteMethod · 0.95
clearMemoryCacheMethod · 0.95
clearAllCacheMethod · 0.95
getKeysInCacheMethod · 0.95
putWithStorageCacheMethod · 0.95
clearStorageCacheMethod · 0.95

Calls 13

currentTimeMillisMethod · 0.95
hasMoreElementsMethod · 0.95
nextElementMethod · 0.95
placeInStorageCacheMethod · 0.95
getInstanceMethod · 0.95
valueOfMethod · 0.95
sizeMethod · 0.65
keysMethod · 0.65
getMethod · 0.65
longValueMethod · 0.65
putMethod · 0.65
removeMethod · 0.65

Tested by 14

putAndGetMethod · 0.76
putMultipleItemsMethod · 0.76
deleteMethod · 0.76
clearMemoryCacheMethod · 0.76
clearAllCacheMethod · 0.76
getKeysInCacheMethod · 0.76
putWithStorageCacheMethod · 0.76
clearStorageCacheMethod · 0.76
updateExistingKeyMethod · 0.76