Cache 类型
模块: cc.AssetManager
用于缓存某些内容
索引
属性(properties)
countNumber缓存数量
方法
constructor创建一个 cacheadd增加键值对到缓存中get通过 key 获取对应的 valuehas通过 Key 判断是否存在对应的内容remove通过 Key 移除对应的内容clear清除所有内容forEach枚举所有内容并执行方法find枚举所有内容,找到一个可以满足条件的元素destroy销毁这个 cache
Details
属性(properties)
count
缓存数量
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/asset-manager/cache.js:239 |
方法
constructor
创建一个 cache
| meta | description |
|---|---|
| 定义于 | cocos2d/core/asset-manager/cache.js:56 |
参数列表
mapObject An object used to initialize
add
增加键值对到缓存中
| meta | description |
|---|---|
| 返回 | Any |
| 定义于 | cocos2d/core/asset-manager/cache.js:71 |
参数列表
keyString The keyvalAny The value
示例
var cache = new Cache();
cache.add('test', null);
get
通过 key 获取对应的 value
| meta | description |
|---|---|
| 返回 | Any |
| 定义于 | cocos2d/core/asset-manager/cache.js:95 |
参数列表
keystring The key
示例
var cache = new Cache();
var test = cache.get('test');
has
通过 Key 判断是否存在对应的内容
| meta | description |
|---|---|
| 返回 | boolean |
| 定义于 | cocos2d/core/asset-manager/cache.js:117 |
参数列表
keystring The key
示例
var cache = new Cache();
var exist = cache.has('test');
remove
通过 Key 移除对应的内容
| meta | description |
|---|---|
| 返回 | Any |
| 定义于 | cocos2d/core/asset-manager/cache.js:139 |
参数列表
keystring The key
示例
var cache = new Cache();
var content = cache.remove('test');
clear
清除所有内容
| meta | description |
|---|---|
| 定义于 | cocos2d/core/asset-manager/cache.js:166 |
示例
var cache = new Cache();
cache.clear();
forEach
枚举所有内容并执行方法
| meta | description |
|---|---|
| 定义于 | cocos2d/core/asset-manager/cache.js:189 |
参数列表
示例
var cache = new Cache();
cache.forEach((val, key) => console.log(key));
find
枚举所有内容,找到一个可以满足条件的元素
| meta | description |
|---|---|
| 返回 | Any |
| 定义于 | cocos2d/core/asset-manager/cache.js:214 |
参数列表
predicateFunction The condition
示例
var cache = new Cache();
var val = cache.find((val, key) => key === 'test');
destroy
销毁这个 cache
| meta | description |
|---|---|
| 定义于 | cocos2d/core/asset-manager/cache.js:253 |