Cache Class
Module: cc.AssetManager
use to cache something
Index
Properties
countNumberThe count of cached content
Methods
constructorCreate a cacheaddAdd Key-Value to cachegetGet the cached content by keyhasCheck whether or not content exists by keyremoveRemove the cached content by keyclearClear all contentforEachEnumerate all content and invoke functionfindEnumerate all content to find one element which can fulfill conditiondestroyDestroy this cache
Details
Properties
count
The count of cached content
| meta | description |
|---|---|
| Type | Number |
| Defined in | cocos2d/core/asset-manager/cache.js:239 |
Methods
constructor
Create a cache
| meta | description |
|---|---|
| Defined in | cocos2d/core/asset-manager/cache.js:56 |
Parameters
mapObject An object used to initialize
add
Add Key-Value to cache
| meta | description |
|---|---|
| Returns | Any |
| Defined in | cocos2d/core/asset-manager/cache.js:71 |
Parameters
keyString The keyvalAny The value
Examples
var cache = new Cache();
cache.add('test', null);
get
Get the cached content by key
| meta | description |
|---|---|
| Returns | Any |
| Defined in | cocos2d/core/asset-manager/cache.js:95 |
Parameters
keystring The key
Examples
var cache = new Cache();
var test = cache.get('test');
has
Check whether or not content exists by key
| meta | description |
|---|---|
| Returns | boolean |
| Defined in | cocos2d/core/asset-manager/cache.js:117 |
Parameters
keystring The key
Examples
var cache = new Cache();
var exist = cache.has('test');
remove
Remove the cached content by key
| meta | description |
|---|---|
| Returns | Any |
| Defined in | cocos2d/core/asset-manager/cache.js:139 |
Parameters
keystring The key
Examples
var cache = new Cache();
var content = cache.remove('test');
clear
Clear all content
| meta | description |
|---|---|
| Defined in | cocos2d/core/asset-manager/cache.js:166 |
Examples
var cache = new Cache();
cache.clear();
forEach
Enumerate all content and invoke function
| meta | description |
|---|---|
| Defined in | cocos2d/core/asset-manager/cache.js:189 |
Parameters
Examples
var cache = new Cache();
cache.forEach((val, key) => console.log(key));
find
Enumerate all content to find one element which can fulfill condition
| meta | description |
|---|---|
| Returns | Any |
| Defined in | cocos2d/core/asset-manager/cache.js:214 |
Parameters
predicateFunction The condition
Examples
var cache = new Cache();
var val = cache.find((val, key) => key === 'test');
destroy
Destroy this cache
| meta | description |
|---|---|
| Defined in | cocos2d/core/asset-manager/cache.js:253 |