diff --git a/engine/src/desktop/com/jme3/asset/AssetCache.java b/engine/src/desktop/com/jme3/asset/AssetCache.java
index b9dbfdb36..5dde799e7 100644
--- a/engine/src/desktop/com/jme3/asset/AssetCache.java
+++ b/engine/src/desktop/com/jme3/asset/AssetCache.java
@@ -84,12 +84,12 @@ public class AssetCache {
* Thread-safe.
*/
public boolean deleteFromCache(AssetKey key){
- if (key.useSmartCache()){
- throw new UnsupportedOperationException("You cannot delete from the smart cache");
- }
-
synchronized (regularCache){
- return regularCache.remove(key) != null;
+ if (key.useSmartCache()){
+ return smartCache.remove(key) != null;
+ }else{
+ return regularCache.remove(key) != null;
+ }
}
}
@@ -125,6 +125,7 @@ public class AssetCache {
public void deleteAllAssets(){
synchronized (regularCache){
regularCache.clear();
+ smartCache.clear();
}
}
}
diff --git a/engine/src/test/jme3test/asset/TestAssetCache.java b/engine/src/test/jme3test/asset/TestAssetCache.java
index e68cca302..066fe211d 100644
--- a/engine/src/test/jme3test/asset/TestAssetCache.java
+++ b/engine/src/test/jme3test/asset/TestAssetCache.java
@@ -32,74 +32,140 @@
package jme3test.asset;
+import com.jme3.asset.Asset;
import com.jme3.asset.AssetCache;
import com.jme3.asset.AssetKey;
+import java.util.ArrayList;
+import java.util.List;
public class TestAssetCache {
+
+ /**
+ * Keep references to loaded assets
+ */
+ private final static boolean KEEP_REFERENCES = false;
+
+ /**
+ * Enable smart cache use
+ */
+ private final static boolean USE_SMART_CACHE = true;
+
+ /**
+ * Enable cloneable asset use
+ */
+ private final static boolean CLONEABLE_ASSET = true;
- private static class MyAsset {
-
- private String name;
- private byte[] bytes = new byte[100];
+ private static int counter = 0;
+
+ private static class DummyData implements Asset {
+
+ private AssetKey key;
+ private byte[] data = new byte[10000];
- public MyAsset(String name) {
- this.name = name;
+ public byte[] getData(){
+ return data;
+ }
+
+ public AssetKey getKey() {
+ return key;
}
- public String getName() {
- return name;
+ public void setKey(AssetKey key) {
+ this.key = key;
+ }
+ }
+
+ private static class SmartKey extends AssetKey {
+
+ public SmartKey(){
+ super(".");
+ counter++;
+ }
+
+ @Override
+ public int hashCode(){
+ return 0;
+ }
+
+ @Override
+ public boolean equals(Object other){
+ return false;
+ }
+
+ @Override
+ public boolean useSmartCache(){
+ return true;
+ }
+
+ @Override
+ public Object createClonedInstance(Object asset){
+ DummyData data = new DummyData();
+ return data;
+ }
+ }
+
+ private static class DumbKey extends AssetKey {
+
+ public DumbKey(){
+ super(".");
+ counter++;
+ }
+
+ @Override
+ public int hashCode(){
+ return 0;
+ }
+
+ @Override
+ public boolean equals(Object other){
+ return false;
}
- }
+ @Override
+ public Object createClonedInstance(Object asset){
+ if (CLONEABLE_ASSET){
+ DummyData data = new DummyData();
+ return data;
+ }else{
+ return asset;
+ }
+ }
+ }
-// private static final long memoryUsage(){
-// return Runtime.getRuntime().
-// }
-//
public static void main(String[] args){
+ List