/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
/**
* MultiLruCache -- in-memory bounded LRU cache with multiple LRU lists
* Underlying Hashtable is made into logical segments, with each segment
* having its own LRU list.
*/
// upper bound on the cache size
protected long currentSize;
/**
* initialize the LRU cache
* @param maxCapacity maximum number of entries this cache may hold
*/
currentSize = 0;
int multiplier = 1;
long size = -1;
int index;
// upper case the string
// look for 200KB or 80Kb or 1MB or 2Mb like suffixes
}
try {
} catch (NumberFormatException nfe) {}
}
// sanity check and convert
if (size > 0)
else {
throw new IllegalArgumentException(msg);
}
}
}
/**
* this item is just added to the cache
* @param item <code>CacheItem</code> that was created
* @return a overflow item; may be null
*
* Cache bucket is already synchronized by the caller
*/
// update the size
}
return overflow;
}
/**
* item value has been refreshed
* @param item <code>CacheItem</code> that was refreshed
* @param oldSize size of the previous value that was refreshed
* Cache bucket is already synchronized by the caller
*/
/** reduce the cache by the size of the size of the previous value
* and increment by the value being refreshed with.
*/
}
/**
* item value has been removed from the cache
* @param item <code>CacheItem</code> that was just removed
*
* Cache bucket is already synchronized by the caller
*/
super.itemRemoved(item);
// update the size
}
/**
* has cache reached its threshold
* @return true when the cache reached its threshold
*/
protected boolean isThresholdReached() {
}
/**
* synchronized counter updates
*/
synchronized(currentSizeLk) {
currentSize += size;
}
}
synchronized(currentSizeLk) {
currentSize -= size;
}
}
/**
* get generic stats from subclasses
*/
/**
* get the desired statistic counter
* @param key to corresponding stat
* @return an Object corresponding to the stat
* See also: Constant.java for the key
*/
else
}
}
return stat;
}
// cache size in KB
}
else {
}
return stats;
}
}