The DataSourceCache plugin enables caching on any DataSource to reduce high-latency calls to remote sources and to reduce server load. In this example, the Cache's `max` value has been set to `3`.

{{>datasource-caching-source}}

Use the plug() method to initialize the DataSourceCache plugin and pass in the configuration value max to set the maximum size.

``` YUI().use("datasource", "dataschema", "cache", function (Y) { var callback = { success: function (e) { /* output to screen */ }, failure: function (e) { /* output to screen */ } }, myDataSource = new Y.DataSource.Get({ source: "https://api.github.com/users/", // this is only needed because the query appends the url // rather than the url's query params generateRequestCallback: function (guid) { return '/repos?callback=YUI.Env.DataSource.callbacks.' + guid; } }), myDataSource.plug(Y.Plugin.DataSourceJSONSchema, { schema: { resultListLocator: "data", resultFields: ["name"] } }); myDataSource.plug(Y.Plugin.DataSourceCache, { max: 3 }); // Adds to cache myDataSource.sendRequest({ request : "lsmith", callback: callback }); // Adds to cache myDataSource.sendRequest({ request : "davglass", callback: callback }); // Retrieves from cache myDataSource.sendRequest({ request : "lsmith", callback: callback }); }); ```

Full Example Source Listing

``` {{>datasource-caching-source}} ```