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

Method setMaxSize

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

Sets the maximum number of elements in the cache. If 0, there is no maximum. @param maxSize The maximum number of elements in the cache

(long maxSize)

Source from the content-addressed store, hash-verified

312 * The maximum number of elements in the cache
313 */
314 public void setMaxSize(long maxSize) {
315 // if the new maxSize is <= 0, clear keyLRUList
316 if (maxSize <= 0) {
317 keyLRUList.clear();
318 } else if (maxSize > 0 && this.maxSize <= 0) {
319 // if the new maxSize > 0 and the old is <= 0, fill in LRU list -
320 // order will be meaningless for now
321 Iterator keys = cacheLineTable.keySet().iterator();
322
323 while (keys.hasNext()) {
324 keyLRUList.add(keys.next());
325 }
326 }
327
328 // if the new maxSize is less than the current cache size, shrink the
329 // cache.
330 if (maxSize > 0 && cacheLineTable.size() > maxSize) {
331 while (cacheLineTable.size() > maxSize) {
332 Object lastKey = keyLRUList.getLast();
333
334 removeObject(lastKey);
335 }
336 }
337
338 this.maxSize = maxSize;
339 }
340
341 /**
342 * Returns the current maximum number of elements in the cache

Callers

nothing calls this directly

Calls 9

removeObjectMethod · 0.95
iteratorMethod · 0.80
getLastMethod · 0.80
clearMethod · 0.65
keySetMethod · 0.65
sizeMethod · 0.65
hasNextMethod · 0.45
addMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected