Configured our LRU image cache to flush images when we reach a certain

number of bytes used rather than a certain image count.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2173 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2003-01-17 02:29:32 +00:00
parent 380762962b
commit 34144c86de
@@ -1,5 +1,5 @@
//
// $Id: ImageManager.java,v 1.43 2003/01/15 02:50:36 mdb Exp $
// $Id: ImageManager.java,v 1.44 2003/01/17 02:29:32 mdb Exp $
package com.threerings.media.image;
@@ -95,8 +95,12 @@ public class ImageManager
// create our image cache
int icsize = _cacheSize.getValue();
Log.debug("Creating image cache [size=" + icsize + "].");
_ccache = new LRUHashMap(icsize);
Log.debug("Creating image cache [size=" + icsize + "k].");
_ccache = new LRUHashMap(icsize * 1024, new LRUHashMap.ItemSizer() {
public int computeSize (Object value) {
return (int)((CacheRecord)value).getEstimatedMemoryUsage();
}
});
// try to figure out which image loader we'll be using
try {
@@ -207,6 +211,9 @@ public class ImageManager
Log.warning("Failed to load image " + key + ".");
}
// Log.info("Loaded " + key.path + ", image=" + image +
// ", size=" + ImageUtil.getEstimatedMemoryUsage(image));
// create a cache record
crec = new CacheRecord(image);
_ccache.put(key, crec);
@@ -499,8 +506,9 @@ public class ImageManager
* framework. */
protected static RuntimeAdjust.IntAdjust _cacheSize =
new RuntimeAdjust.IntAdjust(
"Size (in images) of the image manager LRU cache [requires reboot]",
"narya.media.image.cache_size", MediaPrefs.config, 100);
"Size (in kb of memory used) of the image manager LRU cache " +
"[requires restart]", "narya.media.image.cache_size",
MediaPrefs.config, 2*1024);
/** Controls whether or not we prepare images or use raw versions. */
protected static RuntimeAdjust.BooleanAdjust _prepareImages =