\r
private static final Logger logger = Logger.getLogger(AssetManager.class.getName());\r
\r
- private final AssetCache cache = new AssetCache();\r
+ private final SoftRefCache cache = new SoftRefCache();\r
private final ImplHandler handler = new ImplHandler(this);\r
\r
private AssetEventListener eventListener = null;\r
AssetKey smartKey = null;\r
Object o = null;\r
if (key.shouldCache()){\r
- if (key.useSmartCache()){\r
- SmartAssetInfo smartInfo = cache.getFromSmartCache(key);\r
- if (smartInfo != null){\r
- smartKey = smartInfo.smartKey.get();\r
- if (smartKey != null){\r
- o = smartInfo.asset;\r
- }\r
- }\r
- }else{\r
+// if (key.useSmartCache()){\r
+// SmartAssetInfo smartInfo = cache.getFromSmartCache(key);\r
+// if (smartInfo != null){\r
+// smartKey = smartInfo.smartKey.get();\r
+// if (smartKey != null){\r
+// o = smartInfo.asset;\r
+// }\r
+// }\r
+// }else{\r
o = cache.getFromCache(key);\r
- }\r
+// }\r
}\r
if (o == null){\r
AssetLoader loader = handler.aquireLoader(key);\r
--- /dev/null
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.jme3.asset;
+
+import java.lang.ref.SoftReference;
+import java.util.HashMap;
+
+/**
+ *
+ * @author kobayasi
+ */
+public class SoftRefCache {
+ private final HashMap<AssetKey, SoftReference> cache = new HashMap<AssetKey, SoftReference>();
+ public void addToCache(AssetKey key, Object obj) {
+ cache.put(key, new SoftReference(obj));
+ }
+
+ public void deleteAllAssets() {
+ cache.clear();
+ }
+
+ public boolean deleteFromCache(AssetKey key) {
+ return cache.remove(key) != null;
+ }
+
+ public Object getFromCache(AssetKey key) {
+ SoftReference ref = cache.get(key);
+ if (ref != null) {
+ return ref.get();
+ }
+ return null;
+ }
+
+// public AssetCache.SmartAssetInfo getFromSmartCache(AssetKey key) {
+// SoftReference ref = cache.get(key);
+// if (ref != null) {
+// return ref.get();
+// }
+// return null;
+// }
+
+}