Class: BaseCacheableObject

BaseCacheableObject

The base class for all project objects that can be cached. This class is extremely useful for classes which have unique identifiers but cannot make API calls.

Note: The id used for caching may be different than any id used by the response from the wire. This allows for caching of an instance with the same id but different season data. Example: League with different seasonIds can all be cached using this functionality. See the getCacheId method for implementation.

When managing the cache, never set an object to an undefined id. Always check that the result from getCacheId is valid (see _populateObject for an example). Otherwise the cache will not be in the correct state.

new BaseCacheableObject ()

Extends

Members

BaseCacheableObject.cache static

Returns all cached instances of an BaseCacheableObject. If no cache exists, a cache object is created. This implementation ensures each class has a unique cache of only instances of the BaseCacheableObject that does not overlap with other BaseCacheableObject classes. The keys of the cache should use the caching id implemented in getCacheId.

BaseCacheableObject.cache static

Sets the cache object.

displayName String inherited overrides

The class name. Minification will break this.constructor.name; this allows for readable logging even in minified code.

Methods

BaseCacheableObject._populateObject () static

Defers to BaseObject._populateObject and then caches the instance using the caching id from getCacheId.

BaseCacheableObject.clearCache () static

Resets cache to an empty object.

BaseCacheableObject.get (id)BaseCacheableObject | undefined static

Returns a cached instance matching the passed caching id if it exists. Otherwise, returns undefined.

Name Type Description
id Number

This id must match the form of the caching id provided by getCacheId.

Returns:
Type Description
BaseCacheableObject | undefined

BaseCacheableObject.getCacheId (idParams)string | undefined static

Constructs and returns an id for the cache if possible from the passed params. If construction is not possible, returns undefined.

Name Type Description
idParams Object
Returns:
Type Description
string | undefined

BaseCacheableObject.getIDParams ()Object static

Should be overridden by each subclass. Returns an object containing all IDs used for API requests and caching.

Returns:
Type Description
Object

getCacheId ()String | undefined

Returns the id used for caching. Important for classes that have multiple identifiers. Example: League is identified by its leagueId and its seasonId. This method prevents separate seasons from overriding each other's data.

Returns:
Type Description
String | undefined

getIDParams ()Object

Returns an object containing all IDs used for API requests and caching for the instance.

Returns:
Type Description
Object