Load a model without caching it

In an editor application, caching causes problems. When you write an asset and then read it, you want to get the newer version, not the one in the cache. When I first encountered this, I worked around it by invoking DesktopAssetManager.clearCache() before every load. But this works only on a desktop, and it flushes everything from the cache, not just the one asset I’m trying to load.

So I created a class UncachedModelKey extends AssetKey<Spatial> specifically for the purpose of bypassing the cache during a loadAsset(). In particular, UncachedModelKey.getCacheType() returns null.

So far, so good. My question is, what should UncachedModelKey.getProcessorType() return?

Since Spatial implements CloneableSmartAsset, DesktopAssetManager.registerAndCloneSmartAsset() insists the AssetProcessor cannot be null. But if I return CloneableAssetProcessor.class, I get an IllegalStateException:

Apr 04, 2017 9:39:03 PM com.jme3.app.LegacyApplication handleError
SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.IllegalStateException: Asset implements CloneableSmartAsset but doesn't have cache or was not cloned
	at com.jme3.asset.DesktopAssetManager.registerAndCloneSmartAsset(DesktopAssetManager.java:321)
	at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:379)

1 Like

First, do you imagine a use-case where you are somehow managing to read/write assets on Android?

ie: is there a real use-case when you wouldn’t have a DesktopAssetManager?


Edit: which by the way seems to be available on the AssetManager interface itself… so may work on non DesktopAssetManager cases.


It sounds like AssetManager.deleteFromCache(AssetKey) may be my best solution. Thanks for pointing me there!

1 Like

Just an idea: The AssetManager.loadAssetFromStream function also bypasses the cache, so you could load assets from InputStreams without the need to explicitely uncache them afterwards.


An even cleaner solution. I like it!

1 Like

When I use loadAssetFromStream() to load a J3O model, it works fine, but when I use it to import an OgreXML model, the materials don’t load. (They get set to null.)

1 Like