Model Store

The Model Store is a cache in memory on the client. This will help reduce the number of client-side requests by checking to see if the data is in the store before making a fetch request. Generally, this does not need to be modified, and it is instantiated by the app during the app initialization.

The Model Store is attached to the fetcher class to allow the fetcher to easily verify whether data is in the store before making the AJAX request to the API.

cache ModelStore.cache


An object of models that stores data in memory to reduce the number of round trips to the API. Overriding data or modifying the cache is not recommended, but it is helpful for inspecting the data.

clear ModelStore.clear([modelName], [id])


Removes the model(s) from the cache. If you pass both the modelName and the id it will clear that model from the store. If you only pass the modelName it will clear all of the models of that type in the store. Passing no arguments will clear the entire model store.

expireSeconds ModelStore.expireSeconds


The length of time that the model will be stored, in seconds. By default this is set to null, so the data will not expire until the page is reloaded.

find ModelStore.find(modelName, attrs)


Returns the first instance found that matches the modelName and attrs sent. The modelName is the name of the model, the attrs is an object of parameters to search on.

modelStore.find('Media', { type: "photo", id: 16 })

get ModelStore.get(modelName, id)


Returns the model from the store. Requires the name of the model and the model's id.

set ModelStore.set(model)


Adds the model to the model store. This function generates a key based on the model name and id, then inserts it into the cache.