Methods Summary |
---|
public synchronized boolean | addResource(Resource o)Add resource into cache. Size of resource is checked against
maxResourceSize and cache capacity. Only if resource doesn't exceed
maxResourceSize it's stored in cache. If adding resource would exceeed
max cache size, resources are removed from cache until the resource
could have be en stored.
if (o.getSize() > maxAllowedResourceSize) {
return false;
}
while (cacheSize + o.getSize() > maxCacheCapacity) {
cacheSize -= ((Resource) cache.elementAt(0)).getSize();
cache.removeElementAt(0);
// remove last used element
}
// while
cache.addElement(o);
cacheSize += o.getSize();
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR238,
classname + ": " +
"\nCache: " + this +
"\nResource added to cache\n" +
"\nCache size = " + cacheSize);
}
return true;
|
public int | getHashCodeForResource(java.lang.String base, java.lang.String locale, int id)Calculates hash code for the resource.
int hashCode = new String(locale +
base +
Integer.toString(id)).hashCode();
return hashCode;
|
public synchronized Resource | lookup(int hashCode)Resource is looked up in cache. If resource was found it is returned.
Otherwise null is returned.
Resource o = null;
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR238,
classname + ": " +
"\nCache: " + this +
"\nLooking up resource with key=" + hashCode);
}
for (int i = cache.size() - 1; i >= 0; i--) {
o = (Resource) cache.elementAt(i);
if (cache.elementAt(i).hashCode() == hashCode) {
// move element to front
cache.removeElementAt(i);
cache.addElement(o);
return o;
}
}
// for
return null;
|