MCPcopy Create free account
hub / github.com/banq/jdonframework / put

Method put

src/main/java/com/jdon/cache/UtilCache.java:164–195  ·  view source on GitHub ↗

Puts or loads the passed element into the cache @param key The key for the element, used to reference it in the hastables and LRU linked list @param value The value of the element

(Object key, Object value)

Source from the content-addressed store, hash-verified

162 * The value of the element
163 */
164 public void put(Object key, Object value) {
165 if ((key == null) || (value == null))
166 return;
167
168 try {
169 if (maxSize > 0) {
170 // when maxSize is changed, the setter will take care of filling
171 // the
172 // LRU list
173 if (cacheLineTable.containsKey(key)) {
174 keyLRUList.moveFirst(key);
175 } else {
176 keyLRUList.addFirst(key);
177 }
178 }
179
180 if (expireTime > 0) {
181 cacheLineTable.put(key, new CacheLine(value, useSoftReference, System.currentTimeMillis()));
182 } else {
183 cacheLineTable.put(key, new CacheLine(value, useSoftReference));
184 }
185 if (maxSize > 0 && cacheLineTable.size() > maxSize) {
186 Object lastKey = keyLRUList.getLast();
187 removeObject(lastKey);
188 }
189 } catch (Exception e) {
190 Debug.logError(e);
191 } finally {
192 }
193 Debug.logVerbose("[JdonFramework]cache now size = " + keyLRUList.size() + " maxSize =" + maxSize + " this Cache id:" + this.hashCode(),
194 module);
195 }
196
197 /**
198 * Gets an element from the cache according to the specified key. If the

Callers

nothing calls this directly

Calls 9

removeObjectMethod · 0.95
logErrorMethod · 0.95
logVerboseMethod · 0.95
containsKeyMethod · 0.80
moveFirstMethod · 0.80
addFirstMethod · 0.80
getLastMethod · 0.80
putMethod · 0.65
sizeMethod · 0.65

Tested by

no test coverage detected