Phaser API Documentation

  Version: 
Filter

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.

Constructor:

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

Members

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

Description:

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 31)
Focus
Focus

Description:

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

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

Methods

add(key, data)
Focus
Focus

Description:

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.

Returns:
Description:

This BaseCache object.

Since: 3.0.0
Source: src/cache/BaseCache.js (Line 52)
Focus
Focus
destroy()
Focus
Focus

Description:

Destroys this cache and all items within it.

Since: 3.0.0
Source: src/cache/BaseCache.js (Line 163)
Focus
Focus
exists(key)
Focus
Focus

Description:

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.

Returns:
Description:

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

Type:
  • boolean
Since: 3.7.0
Source: src/cache/BaseCache.js (Line 90)
Focus
Focus
get(key)
Focus
Focus

Description:

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.

Returns:
Description:

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

Type:
  • *
Since: 3.0.0
Source: src/cache/BaseCache.js (Line 106)
Focus
Focus
getKeys()
Focus
Focus

Description:

Returns all keys in use in this cache.

Returns:
Description:

Array containing all the keys.

Type:
  • Array.<string>
Since: 3.17.0
Source: src/cache/BaseCache.js (Line 150)
Focus
Focus
has(key)
Focus
Focus

Description:

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.

Returns:
Description:

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

Type:
  • boolean
Since: 3.0.0
Source: src/cache/BaseCache.js (Line 74)
Focus
Focus
remove(key)
Focus
Focus

Description:

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.

Returns:
Description:

This BaseCache object.

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