public synchronized Object remove(Object key) { return remove(key, false); }
public synchronized V remove(Object key) { return remove(key, false); }
public synchronized V remove(Object key) { return remove(key, false); }
public synchronized V remove(Object key) { return remove(key, false); }
public synchronized void clear() { Object[] keys = map.keySet().toArray(); for (Object key : keys) { remove(key); } // Now, reset all containers. map.clear(); lastAccessedList.clear(); ageList.clear(); cacheHits = 0; cacheMisses = 0; }
public synchronized void clear() { Object[] keys = map.keySet().toArray(); for (int i = 0; i < keys.length; i++) { remove(keys[i]); } // Now, reset all containers. map.clear(); lastAccessedList.clear(); ageList.clear(); cacheHits = 0; cacheMisses = 0; }
public synchronized void clear() { Object[] keys = map.keySet().toArray(); for (Object key : keys) { remove(key); } // Now, reset all containers. map.clear(); lastAccessedList.clear(); ageList.clear(); cacheHits = 0; cacheMisses = 0; }
public synchronized void clear() { Object[] keys = map.keySet().toArray(); for (Object key : keys) { remove(key); } // Now, reset all containers. map.clear(); lastAccessedList.clear(); ageList.clear(); cacheHits = 0; cacheMisses = 0; }
public synchronized V put(K key, V value) { V oldValue = null; // Delete an old entry if it exists. if (map.containsKey(key)) { oldValue = remove(key, true); } CacheObject<V> cacheObject = new CacheObject<V>(value); map.put(key, cacheObject); // Make an entry into the cache order list. // Store the cache order list entry so that we can get back to it // during later lookups. cacheObject.lastAccessedListNode = lastAccessedList.addFirst(key); // Add the object to the age list LinkedListNode ageNode = ageList.addFirst(key); ageNode.timestamp = System.currentTimeMillis(); cacheObject.ageListNode = ageNode; // If cache is too full, remove least used cache entries until it is not too full. cullCache(); return oldValue; }
public synchronized Object put(Object key, Object value) { Object oldValue = null; // Delete an old entry if it exists. if (map.containsKey(key)) { oldValue = remove(key, true); } CacheObject cacheObject = new CacheObject(value); map.put(key, cacheObject); // Make an entry into the cache order list. // Store the cache order list entry so that we can get back to it // during later lookups. cacheObject.lastAccessedListNode = lastAccessedList.addFirst(key); // Add the object to the age list LinkedListNode ageNode = ageList.addFirst(key); ageNode.timestamp = System.currentTimeMillis(); cacheObject.ageListNode = ageNode; // If cache is too full, remove least used cache entries until it is not too full. cullCache(); return oldValue; }
public synchronized V put(K key, V value) { V oldValue = null; // Delete an old entry if it exists. if (map.containsKey(key)) { oldValue = remove(key, true); } CacheObject<V> cacheObject = new CacheObject<V>(value); map.put(key, cacheObject); // Make an entry into the cache order list. // Store the cache order list entry so that we can get back to it // during later lookups. cacheObject.lastAccessedListNode = lastAccessedList.addFirst(key); // Add the object to the age list LinkedListNode ageNode = ageList.addFirst(key); ageNode.timestamp = System.currentTimeMillis(); cacheObject.ageListNode = ageNode; // If cache is too full, remove least used cache entries until it is not too full. cullCache(); return oldValue; }
public synchronized V put(K key, V value) { V oldValue = null; // Delete an old entry if it exists. if (map.containsKey(key)) { oldValue = remove(key, true); } CacheObject<V> cacheObject = new CacheObject<V>(value); map.put(key, cacheObject); // Make an entry into the cache order list. // Store the cache order list entry so that we can get back to it // during later lookups. cacheObject.lastAccessedListNode = lastAccessedList.addFirst(key); // Add the object to the age list LinkedListNode ageNode = ageList.addFirst(key); ageNode.timestamp = System.currentTimeMillis(); cacheObject.ageListNode = ageNode; // If cache is too full, remove least used cache entries until it is not too full. cullCache(); return oldValue; }
if (remove(node.object, true) == null) { System.err.println("Error attempting to remove(" + node.object.toString() + ") - cacheObject not found in cache!");
if (remove(node.object, true) == null) { System.err.println("Error attempting to remove(" + node.object.toString() + ") - cacheObject not found in cache!");
if (remove(node.object, true) == null) { System.err.println("Error attempting to remove(" + node.object.toString() + ") - cacheObject not found in cache!");
if (remove(node.object, true) == null) { System.err.println("Error attempting to remove(" + node.object.toString() + ") - cacheObject not found in cache!");
/** * Removes the least recently used elements if the cache size is greater than * or equal to the maximum allowed size until the cache is at least 10% empty. */ protected synchronized void cullCache() { // Check if a max cache size is defined. if (maxCacheSize < 0) { return; } // See if the cache is too big. If so, clean out cache until it's 10% free. if (map.size() > maxCacheSize) { // First, delete any old entries to see how much memory that frees. deleteExpiredEntries(); // Next, delete the least recently used elements until 10% of the cache // has been freed. int desiredSize = (int) (maxCacheSize * .90); for (int i=map.size(); i>desiredSize; i--) { // Get the key and invoke the remove method on it. if (remove(lastAccessedList.getLast().object, true) == null) { System.err.println("Error attempting to cullCache with remove(" + lastAccessedList.getLast().object.toString() + ") - " + "cacheObject not found in cache!"); lastAccessedList.getLast().remove(); } } } }
/** * Removes the least recently used elements if the cache size is greater than * or equal to the maximum allowed size until the cache is at least 10% empty. */ protected synchronized void cullCache() { // Check if a max cache size is defined. if (maxCacheSize < 0) { return; } // See if the cache is too big. If so, clean out cache until it's 10% free. if (map.size() > maxCacheSize) { // First, delete any old entries to see how much memory that frees. deleteExpiredEntries(); // Next, delete the least recently used elements until 10% of the cache // has been freed. int desiredSize = (int) (maxCacheSize * .90); for (int i=map.size(); i>desiredSize; i--) { // Get the key and invoke the remove method on it. if (remove(lastAccessedList.getLast().object, true) == null) { System.err.println("Error attempting to cullCache with remove(" + lastAccessedList.getLast().object.toString() + ") - " + "cacheObject not found in cache!"); lastAccessedList.getLast().remove(); } } } }
/** * Removes the least recently used elements if the cache size is greater than * or equal to the maximum allowed size until the cache is at least 10% empty. */ protected synchronized void cullCache() { // Check if a max cache size is defined. if (maxCacheSize < 0) { return; } // See if the cache is too big. If so, clean out cache until it's 10% free. if (map.size() > maxCacheSize) { // First, delete any old entries to see how much memory that frees. deleteExpiredEntries(); // Next, delete the least recently used elements until 10% of the cache // has been freed. int desiredSize = (int) (maxCacheSize * .90); for (int i=map.size(); i>desiredSize; i--) { // Get the key and invoke the remove method on it. if (remove(lastAccessedList.getLast().object, true) == null) { System.err.println("Error attempting to cullCache with remove(" + lastAccessedList.getLast().object.toString() + ") - " + "cacheObject not found in cache!"); lastAccessedList.getLast().remove(); } } } }
/** * Removes the least recently used elements if the cache size is greater than * or equal to the maximum allowed size until the cache is at least 10% empty. */ protected synchronized void cullCache() { // Check if a max cache size is defined. if (maxCacheSize < 0) { return; } // See if the cache is too big. If so, clean out cache until it's 10% free. if (map.size() > maxCacheSize) { // First, delete any old entries to see how much memory that frees. deleteExpiredEntries(); // Next, delete the least recently used elements until 10% of the cache // has been freed. int desiredSize = (int) (maxCacheSize * .90); for (int i=map.size(); i>desiredSize; i--) { // Get the key and invoke the remove method on it. if (remove(lastAccessedList.getLast().object, true) == null) { System.err.println("Error attempting to cullCache with remove(" + lastAccessedList.getLast().object.toString() + ") - " + "cacheObject not found in cache!"); lastAccessedList.getLast().remove(); } } } }