datajs cache - Firefox warning

May 31, 2011 at 12:33 PM

Hello,

I am asking about default warning from Firefox when you want to cache data using datajs library:

This website (localhost) is asking to store data on your computer for offline use.

I am using Firefox 4.0.1

Is there a way, fix for this browser to avoid this annoying message?

Vlatko Ivanovski

Jun 1, 2011 at 7:03 PM

Hi Vlatko,

Hope you are doing great. In Firefox 4.0 the data cache and store APIs will use Indexed DB as the "best" mechanism available so hence the warning. By default Firefox 4.0 is configured to warn the user when a web app tries to use Indexed DB local storage for the first time. You can disable the warning from the Firefox options dialog by selecting Advanced, then Network Tab and deselect the check box "Tell me when a website asks to store data for offline use".

By default, when creating a data cache object the library will try to use the "best" available mechanism in the browser. This means that currently, if Indexed DB is available the library will try to use it; otherwise it will try to use DOM Storage. If none is available, then the library defaults to a volatile in-memory storage that goes away when the web app is refreshed. You can control which storage you want to use for the cache by setting the mechanism property in the options object passed as an argument to the datajs.createDataChache() API. For example, the following snippet will create a data cache object that uses DOM Storage as the underlying store:

var cache = datajs.createDataCache({
   name: "sessions", 
   source: http://live.visitmix.com/odata/Sessions,
   mechanism: "dom"
});

 

The valid values for the mechanism property are:

"best" // the library sniffs the browser and determines the best mechanism available.
"indexeddb" // uses Indexed DB as the underlying store.
"dom" // uses DOM Storage as the underlying store.
"memory" // uses an In-Memory volatile store.
undefined // defaults to best.

Now, the library will only fallback gracefully when mechanism is set to "best" or undefined. If you select a specific mechanism and it is not available, an exception will be thrown and your code will have to handle it. So for example, the snippet will work fine in Firefox 3.6 and later, IE9, IE8, Chrome 8 and later, but will throw an exception in IE6 and other browsers that don't support DOM Storage.

Regards,

Alex Trigo.