public class WeakRefAssetCache extends java.lang.Object implements AssetCache
AssetProcessor.createClone(java.lang.Object)
for that asset
returns the same object as the argument.
This implementation will remove the asset from the cache
once the asset is no longer referenced in user code and memory is low,
e.g. the VM feels like purging the weak references for that asset.Constructor and Description |
---|
WeakRefAssetCache() |
Modifier and Type | Method and Description |
---|---|
<T> void |
addToCache(AssetKey<T> key,
T obj)
Adds an asset to the cache.
|
void |
clearCache()
Deletes all assets from the cache.
|
boolean |
deleteFromCache(AssetKey key)
Deletes an asset from the cache.
|
<T> T |
getFromCache(AssetKey<T> key)
Retrieves an asset from the cache.
|
void |
notifyNoAssetClone()
Notifies the cache that even though the methods
AssetCache.addToCache(com.jme3.asset.AssetKey, java.lang.Object)
or AssetCache.getFromCache(com.jme3.asset.AssetKey) were used, there won't
be a call to AssetCache.registerAssetClone(com.jme3.asset.AssetKey, java.lang.Object)
for some reason. |
<T> void |
registerAssetClone(AssetKey<T> key,
T clone)
This should be called by the asset manager when it has successfully
acquired a cached asset (with
AssetCache.getFromCache(com.jme3.asset.AssetKey) )
and cloned it for use. |
public <T> void addToCache(AssetKey<T> key, T obj)
AssetCache
AssetCache.getFromCache(com.jme3.asset.AssetKey)
method.
However, the caching criteria may at some point decide that the asset
should be removed from the cache to save memory. In that case,
AssetCache.getFromCache(com.jme3.asset.AssetKey)
will return null.
Thread-Safe
addToCache
in interface AssetCache
T
- The type of the asset to cache.key
- The asset key that can be used to look up the asset.obj
- The asset data to cache.public <T> T getFromCache(AssetKey<T> key)
AssetCache
AssetCache.addToCache(com.jme3.asset.AssetKey, java.lang.Object)
.
The asset may be removed from the cache automatically even if
it was added previously, in that case, this method will return null.
Thread-Safe
getFromCache
in interface AssetCache
T
- The type of the asset to retrievekey
- The key used to look up the asset.public boolean deleteFromCache(AssetKey key)
AssetCache
Thread-Safe
deleteFromCache
in interface AssetCache
key
- The asset key to find the asset to delete.public void clearCache()
AssetCache
Thread-Safe
clearCache
in interface AssetCache
public <T> void registerAssetClone(AssetKey<T> key, T clone)
AssetCache
AssetCache.getFromCache(com.jme3.asset.AssetKey)
)
and cloned it for use.
Thread-Safe
registerAssetClone
in interface AssetCache
T
- The type of the asset to register.key
- The asset key of the loaded asset (used to retrieve from cache)clone
- The clone of the asset retrieved from
the cache.public void notifyNoAssetClone()
AssetCache
AssetCache.addToCache(com.jme3.asset.AssetKey, java.lang.Object)
or AssetCache.getFromCache(com.jme3.asset.AssetKey)
were used, there won't
be a call to AssetCache.registerAssetClone(com.jme3.asset.AssetKey, java.lang.Object)
for some reason. For example, if an error occurred during loading
or if the addToCache/getFromCache were used from user code.notifyNoAssetClone
in interface AssetCache