Cache Class

Module: cc.AssetManager

use to cache something

Index

Properties
  • count Number The count of cached content
Methods
  • constructor Create a cache
  • add Add Key-Value to cache
  • get Get the cached content by key
  • has Check whether or not content exists by key
  • remove Remove the cached content by key
  • clear Clear all content
  • forEach Enumerate all content and invoke function
  • find Enumerate all content to find one element which can fulfill condition
  • destroy 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 key
  • val 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
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
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
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
  • func Function Function to be invoked
    • val The value
    • key String The corresponding key
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
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

results matching ""

    No results matching ""