Cache
Class
Module: cc.AssetManager
use to cache something
Index
Properties
count
Number
The count of cached content
Methods
constructor
Create a cacheadd
Add Key-Value to cacheget
Get the cached content by keyhas
Check whether or not content exists by keyremove
Remove the cached content by keyclear
Clear all contentforEach
Enumerate all content and invoke functionfind
Enumerate all content to find one element which can fulfill conditiondestroy
Destroy 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
map
Object 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
key
String The keyval
Any 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
key
string 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
key
string 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
key
string 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
predicate
Function 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 |