public class WeakRefCloneAssetCache extends java.lang.Object implements AssetCache
WeakRefCloneAssetCache
caches cloneable assets in a weak-key
cache, allowing them to be collected when memory is low.
The cache stores weak references to the asset keys, so that
when all clones of the original asset are collected, will cause the
asset to be automatically removed from the cache.Constructor and Description |
---|
WeakRefCloneAssetCache() |
Modifier and Type | Method and Description |
---|---|
<T> void |
addToCache(AssetKey<T> originalKey,
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> originalKey, 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.originalKey
- The asset key that can be used to look up the asset.obj
- The asset data to cache.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
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