For persistent caching of data between application sessions.
This object is intended to provide local storage for data to speed up applications. It can be used as in conjunction with, or as an alternative to the HTML5 local database. Its methods provide features similar to browser cookies and file caching.
For cookies, the intention is that you would use setCookie to save string data in name-value pairs. Cookies persist between application sessions. Data values may be retrieved using the getCookie command or from the getCookieList command as soon as the"intel.xdk.device.ready" event is fired.The media cache commands are meant to provide quicker access to files such as videos and images. Adding files to the media cache will expedite access to them when the application runs. These are files that are cached across sessions and are not in your application bundle. See the section on events below for more information about events fired from the cache section of intel.xdk.
Object |
Type |
Notes |
---|---|---|
intel.xdk.cache.addToMediaCache | method | This command will get a file from the Internet and cache it locally on the device.More details |
intel.xdk.cache.addToMediaCacheExt | method | This method will get a file from the Internet and cache it locally on the device. More details |
intel.xdk.cache.clearAllCookies | method | This method will clear all data stored using the setCookie method. More details |
intel.xdk.cache.clearMediaCache | method | This method will remove all files from the local cache on the device. More details |
intel.xdk.cache.getCookie | method | This method will retrieve the value of a cookie previously saved using the setCookie command. More details |
intel.xdk.cache.getCookieList | method | This method will return an array containing the names of all the previously saved cookies using the setCookie command. More details |
intel.xdk.cache.getMediaCacheList | method | This method will get an array containing all the names of all the previously cached files. More details |
intel.xdk.cache.getMediaCacheLocalURL | method | This method will return an url that you can use to access a cached media file. More details |
intel.xdk.cache.removeCookie | method | This method will clear data previously saved using the setCookie method. More details |
intel.xdk.cache.removeFromMediaCache | method | This method will remove a file from the local cache on the device. More details |
intel.xdk.cache.setCookie | method | This method will set a chunk of data that will persist from session to session. More details |
intel.xdk.cache.media.add | event | This event fires when data is cached. More details |
intel.xdk.cache.media.clear | event | This event fires once all files are removed from the local file cache. More details |
intel.xdk.cache.media.remove | event | This event fires when data is removed from te cache. More details |
intel.xdk.cache.media.update | event | This event fires repeatedly to track caching progress. More details |
Supplemental Documentation
This command will get a file from the Internet and cache it locally on the device. It can then be referenced in a special directory named _mediacache off the root of the bundle. Once this command is run, the“intel.xdk.cache.media.add” event is fired. If there is already a file cached with that name it is overwritten.
intel.xdk.cache.addToMediaCache(urlToCache); function cacheUpdated(e){ alert(e.url + " cached successfully"); } document.addEventListener("intel.xdk.cache.media.add", cacheUpdated, false);
This command will get a file from the Internet and cache it locally on the device. It can then be referenced in a special directory named _mediacache off the root of the bundle. As this method is executed, the "intel.xdk.cache.media.update" event is fired repeatedly to track the progress of the file caching. If there is already a file cached with that name it is overwritten. As the file is cached by this method, a unique id is returned in order to identify their origin. This command will replace the depreciated command addToMediaCache.
intel.xdk.cache.addToMediaCacheExt(urlToCache, uniqueID); function cacheUpdated(evt) { var outString = ""; outString += "current bytes downloaded: " + evt.current; outString += " total bytes in download: " + evt.total; var percentage = evt.current / evt.total outString += " percentage downloaded: " + percentage + "%"; outString += " the unique id is: " + evt.id; outString += "the URL is: " + evt.url; alert(outString); } function cacheComplete(evt) { var outString = ""; outString += "The procedure succeeded (" + evt.success + ") "; outString += " the unique id is: " + evt.id; outString += "the URL is: " + evt.url; alert(outString); } document.addEventListener("intel.xdk.cache.media.update", cacheUpdated, false); document.addEventListener("intel.xdk.cache.media.add", cacheComplete, false);
This method will clear all data stored using the setCookie method.
intel.xdk.cache.clearAllCookies();
This command will remove all files from the local cache on the device. Once this command is run the “intel.xdk.cache.media.clear” event is fired.
intel.xdk.cache.clearMediaCache(); function cacheCleared(){ alert("cache cleared successfully"); } document.addEventListener("intel.xdk.cache.media.clear", cacheCleared, false);
This method will get the value of a cookie previously saved using the setCookie command. If no such cookie exists, the value returned will be “undefined”.
var value = intel.xdk.cache.getCookie("userid");
This method will get the value of a cookie previously saved using the setCookie command. If no such cookie exists, the value returned will be “undefined”.
var value = intel.xdk.cache.getCookie("userid");
This method will return an array containing all the names of all the previously saved cookies using the setCookie command. These names can then be used in calls to getCookie.
var cookiesArray = intel.xdk.cache.getCookieList(); for (var x=0;x
This method will get an array containing all the names of all the previously cached files using the addToMediaCache command. These names can then be used in calls to getMediaCacheLocalURL.
var cacheArray = intel.xdk.cache.getMediaCacheList(); for (var x=0;x
This method will return an url that you can use to access the cached media file. If the requested URL is not cached, the value returned will be "undefined".
var localurl = intel.xdk.cache.getMediaCacheLocalURL("http://myweb.com/image/logo.gif");
This method will clear data previously saved using the setCookie method.
intel.xdk.cache.removeCookie("userid");
This command will remove a file from the local cache on the device. Once this command is run the “intel.xdk.cache.media.remove” event is fired.
intel.xdk.cache.removeFromMediaCache(urlToRemove); function cacheUpdated(e){ alert(e.url + " removed successfully"); } document.addEventListener("intel.xdk.cache.media.remove", cacheUpdated, false);
Call this method to set a chunk of data that will persist from session to session. The data is automatically purged once the expiration date lapses. The data can be retrieved using the getCookie command.
function saveInfo() { //add a cookie var name = prompt('Enter information name:'); var value = prompt('Enter information value:'); var daysTillExpiry = prompt('Days until cookie expires (-1 for never):'); try { if (name.indexOf('.')== -1){ intel.xdk.cache.setCookie(name,value,daysTillExpiry); } else{ alert('cookie names may not include a period'); } } catch(e) { alert("error in saveInfo: " + e.message); } }
This event fires once a file is added to the local file cache using the intel.xdk.cache.addToMediaCache command. The url property on the event object will contain the URL of the remote file cached.
This event fires once all files are removed from the local file cache using the intel.xdk.cache.clearMediaCache command.
This event fires once a file is removed from the local file cache using the intel.xdk.cache.removeFromMediaCache command.
This event is fired repeatedly as the intel.xdk.cache.addToMediaCacheExt method runs. It will return an event object that contains several parameters. The first parameter is the URL of the remote file cached. The second is the unique ID assigned when the command was called. The third is the current number of bytes downloaded and cached so far, and the final parameter is the total number of bytes in the file.
This is space for login message
Login