public interface AssetCache
AssetCache
is an interface for asset caches.
Allowing storage of loaded resources in order to improve their access time
if they are requested again in a short period of time.
Depending on the asset type and how it is used, a specialized
caching method can be selected that is most appropriate for that asset type.
The asset cache must be thread safe.
Some caches are used to manage cloneable assets, which track reachability
based on a shared key in all instances exposed in user code.
E.g. WeakRefCloneAssetCache
uses this approach.
For those particular caches, either registerAssetClone(com.jme3.asset.AssetKey, java.lang.Object)
or notifyNoAssetClone()
MUST be called to avoid memory
leaking following a successful addToCache(com.jme3.asset.AssetKey, java.lang.Object)
or getFromCache(com.jme3.asset.AssetKey)
call!
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
addToCache(com.jme3.asset.AssetKey, java.lang.Object)
or getFromCache(com.jme3.asset.AssetKey) were used, there won't
be a call to 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
getFromCache(com.jme3.asset.AssetKey) )
and cloned it for use. |
<T> void addToCache(AssetKey<T> key, T obj)
getFromCache(com.jme3.asset.AssetKey)
method.
However the caching criteria may at some point choose that the asset
should be removed from the cache to save memory, in that case,
getFromCache(com.jme3.asset.AssetKey)
will return null.
Thread-Safe
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.<T> void registerAssetClone(AssetKey<T> key, T clone)
getFromCache(com.jme3.asset.AssetKey)
)
and cloned it for use.
Thread-Safe
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.void notifyNoAssetClone()
addToCache(com.jme3.asset.AssetKey, java.lang.Object)
or getFromCache(com.jme3.asset.AssetKey)
were used, there won't
be a call to 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.<T> T getFromCache(AssetKey<T> key)
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
T
- The type of the asset to retrievekey
- The key used to lookup the asset.boolean deleteFromCache(AssetKey key)
Thread-Safe
key
- The asset key to find the asset to delete.void clearCache()
Thread-Safe