dojo/cache

Summary

A getter and setter for storing the string content associated with the module and url arguments.

If module is a string that contains slashes, then it is interpretted as a fully resolved path (typically a result returned by require.toUrl), and url should not be provided. This is the preferred signature. If module is a string that does not contain slashes, then url must also be provided and module and url are used to call dojo.moduleUrl() to generate a module URL. This signature is deprecated. If value is specified, the cache value for the moduleUrl will be set to that value. Otherwise, dojo.cache will fetch the moduleUrl and store it in its internal cache and return that cached value for the URL. To clear a cache value pass null for value. Since XMLHttpRequest (XHR) is used to fetch the the URL contents, only modules on the same domain of the page can use this capability. The build system can inline the cache values though, to allow for xdomain hosting.

Usage

cache(module,url,value);
Parameter Type Description
module String | Object

dojo/cldr/supplemental

url String

The rest of the path to append to the path derived from the module argument. If module is an object, then this second argument should be the "value" argument instead.

value String | Object
Optional

If a String, the value to use in the cache for the module/url combination. If an Object, it can have two properties: value and sanitize. The value property should be the value to use in the cache, and sanitize can be set to true or false, to indicate if XML declarations should be removed from the value and if the HTML inside a body tag in the value should be extracted as the real value. The value argument or the value property on the value argument are usually only used by the build system as it inlines cache content.

Returns: undefined | null

See the dojo/cache reference documentation for more information.

Examples

Example 1

To ask dojo.cache to fetch content and store it in the cache (the dojo["cache"] style of call is used to avoid an issue with the build system erroneously trying to intern this example. To get the build system to intern your dojo.cache calls, use the "dojo.cache" style of call):

//If template.html contains "<h1>Hello</h1>" that will be
//the value for the text variable.
//Note: This is pre-AMD, deprecated syntax
var text = dojo["cache"]("my.module", "template.html");

Example 2

To ask dojo.cache to fetch content and store it in the cache, and sanitize the input (the dojo["cache"] style of call is used to avoid an issue with the build system erroneously trying to intern this example. To get the build system to intern your dojo.cache calls, use the "dojo.cache" style of call):

//If template.html contains "<html><body><h1>Hello</h1></body></html>", the
//text variable will contain just "<h1>Hello</h1>".
//Note: This is pre-AMD, deprecated syntax
var text = dojo["cache"]("my.module", "template.html", {sanitize: true});

Example 3

Same example as previous, but demonstrates how an object can be passed in as the first argument, then the value argument can then be the second argument.

//If template.html contains "<html><body><h1>Hello</h1></body></html>", the
//text variable will contain just "<h1>Hello</h1>".
//Note: This is pre-AMD, deprecated syntax
var text = dojo["cache"](new dojo._Url("my/module/template.html"), {sanitize: true});

Methods

© 2005–2017 JS Foundation
Licensed under the AFL 2.1 and BSD 3-Clause licenses.
http://dojotoolkit.org/api/1.10/dojo/cache.html