API Docs for: 1.0.1

Grape.Cacheable Class

Provides a cache feature for a resource: when a resource is loaded multiple times, the expensive operations are executed only once. The resource uses the loadResource method to tell what to do when the resource should be actually loaded. A typical usage is for tile maps, when multiple sprites are on the same image.

Constructor

Grape.Cacheable

()

Methods

getEstimatedTime

() Number

Returns the estimated time to load the resource. Can be overridden.

Returns:

Number:

The estimated time

getResourceKey

()

An abstract method which should return the same key when the resource is the same, it is used as cache key. A typical key is the url.

load

(
  • onFinish
  • onError
  • onProgress
)

Called when the resource is needed to load.

Parameters:

  • onFinish Function

    have to be called when the resource is finished

  • onError Function

    have to be called when an error occurs

  • onProgress Function

    may be called when the progress changes (value in percent)

loadResource

(
  • onFinish
  • onError
  • onProgress
)

This method is called when we want to load the resource and it is not in the cache.

Parameters:

  • onFinish Function

    Should be called when the resource is ready. The parameter is the loaded data.

  • onError Function

    Should be called when an error occurs

  • onProgress Function

    Should be called when the loading progress changes (0-100)

process

(
  • (*)
)

This method is called after load is called. If load is called multiple times, this method is not called more than once. It should initialize the resource with the loaded data.

Parameters:

  • (*) Object

    data The loaded data (passed to the onFinish method in loadResource