Quantcast
Channel: Intermédiaire
Viewing all articles
Browse latest Browse all 677

intel.xdk.cache

$
0
0

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.addToMediaCachemethodThis command will get a file from the Internet and cache it locally on the device.More details
intel.xdk.cache.addToMediaCacheExtmethodThis method will get a file from the Internet and cache it locally on the device. More details
intel.xdk.cache.clearAllCookiesmethodThis method will clear all data stored using the setCookie method. More details
intel.xdk.cache.clearMediaCachemethodThis method will remove all files from the local cache on the device. More details
intel.xdk.cache.getCookiemethodThis method will retrieve the value of a cookie previously saved using the setCookie command. More details
intel.xdk.cache.getCookieListmethodThis method will return an array containing the names of all the previously saved cookies using the setCookie command. More details
intel.xdk.cache.getMediaCacheListmethodThis method will get an array containing all the names of all the previously cached files. More details
intel.xdk.cache.getMediaCacheLocalURLmethodThis method will return an url that you can use to access a cached media file. More details
intel.xdk.cache.removeCookiemethodThis method will clear data previously saved using the setCookie method. More details
intel.xdk.cache.removeFromMediaCachemethodThis method will remove a file from the local cache on the device. More details
intel.xdk.cache.setCookiemethodThis method will set a chunk of data that will persist from session to session. More details
intel.xdk.cache.media.addeventThis event fires when data is cached. More details
intel.xdk.cache.media.cleareventThis event fires once all files are removed from the local file cache. More details
intel.xdk.cache.media.removeeventThis event fires when data is removed from te cache. More details
intel.xdk.cache.media.updateeventThis event fires repeatedly to track caching progress. More details

Supplemental Documentation

addToMediaCache

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);
addToMediaCacheExt

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);
clearAllCookies

This method will clear all data stored using the setCookie method.


        intel.xdk.cache.clearAllCookies();
clearMediaCache

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);
getCookie

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");
getCookie

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");
getCookieList

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<cookiesarray.length alert></cookiesarray.length>
getMediaCacheList

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<cachearray.length alert cachearray intel.xdk.cache.getmediacachelocalurl></cachearray.length>
getMediaCacheLocalURL

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");
removeCookie

This method will clear data previously saved using the setCookie method.


        intel.xdk.cache.removeCookie("userid");
removeFromMediaCache

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);
setCookie

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);
            }
        }
media.add

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.

media.clear

This event fires once all files are removed from the local file cache using the intel.xdk.cache.clearMediaCache command.

media.remove

This event fires once a file is removed from the local file cache using the intel.xdk.cache.removeFromMediaCache command.

media.update

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

Viewing all articles
Browse latest Browse all 677

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>