Class: BaseCache

Phaser.Cache. BaseCache

The BaseCache is a base Cache class that can be used for storing references to any kind of data.

Data can be added, retrieved and removed based on the given keys.

Keys are string-based.


new BaseCache()

Since: 3.0.0
Source: src/cache/BaseCache.js (Line 11)

Members


entries :Phaser.Structs.Map.<String, *>

The Map in which the cache objects are stored.

You can query the Map directly or use the BaseCache methods.

Type:
Since: 3.0.0
Source: src/cache/BaseCache.js (Line 30)

events :Phaser.Events.EventEmitter

An instance of EventEmitter used by the cache to emit related events.

Type:
Since: 3.0.0
Source: src/cache/BaseCache.js (Line 41)

Methods


add(key, data)

Adds an item to this cache. The item is referenced by a unique string, which you are responsible
for setting and keeping track of. The item can only be retrieved by using this string.

Parameters:
Name Type Description
key string

The unique key by which the data added to the cache will be referenced.

data *

The data to be stored in the cache.

Since: 3.0.0
Source: src/cache/BaseCache.js (Line 62)
Fires:
Returns:

This BaseCache object.

Type
Phaser.Cache.BaseCache

destroy()

Destroys this cache and all items within it.

Since: 3.0.0
Source: src/cache/BaseCache.js (Line 171)

exists(key)

Checks if this cache contains an item matching the given key.
This performs the same action as BaseCache.has and is called directly by the Loader.

Parameters:
Name Type Description
key string

The unique key of the item to be checked in this cache.

Since: 3.7.0
Source: src/cache/BaseCache.js (Line 100)
Returns:

Returns true if the cache contains an item matching the given key, otherwise false.

Type
boolean

get(key)

Gets an item from this cache based on the given key.

Parameters:
Name Type Description
key string

The unique key of the item to be retrieved from this cache.

Since: 3.0.0
Source: src/cache/BaseCache.js (Line 116)
Returns:

The item in the cache, or null if no item matching the given key was found.

Type
*

has(key)

Checks if this cache contains an item matching the given key.
This performs the same action as BaseCache.exists.

Parameters:
Name Type Description
key string

The unique key of the item to be checked in this cache.

Since: 3.0.0
Source: src/cache/BaseCache.js (Line 84)
Returns:

Returns true if the cache contains an item matching the given key, otherwise false.

Type
boolean

remove(key)

Removes and item from this cache based on the given key.

If an entry matching the key is found it is removed from the cache and a remove event emitted.
No additional checks are done on the item removed. If other systems or parts of your game code
are relying on this item, it is up to you to sever those relationships prior to removing the item.

Parameters:
Name Type Description
key string

The unique key of the item to remove from the cache.

Since: 3.0.0
Source: src/cache/BaseCache.js (Line 142)
Fires:
Returns:

This BaseCache object.

Type
Phaser.Cache.BaseCache

Events


addEvent

Cache add event.

This event is fired by the Cache each time a new object is added to it.

Parameters:
Name Type Description
cache Phaser.Cache.BaseCache

The BaseCache to which the object was added.

key string

The key of the object added to the cache.

object *

A reference to the object added to the cache.

Source: src/cache/BaseCache.js (Line 51)

removeEvent

Cache remove event.

This event is fired by the Cache each time an object is removed from it.

Parameters:
Name Type Description
cache Phaser.Cache.BaseCache

The BaseCache from which the object was removed.

key string

The key of the object removed from the cache.

object *

The object that was removed from the cache.

Source: src/cache/BaseCache.js (Line 131)