public class Offline
extends java.lang.Object
As well as providing straightforward APIs for storing, retrieving and removing values, Offline support is integrated into the normal request/response cycle. You can configure the framework so that server responses are automatically cached in Offline storage. Then, at some future point when the client is offline, responses for known requests are returned from the Offline cache.
Smart GWT makes use of various underlying storage techniques, depending on what the browser supports, but the API to a Smart GWT program is the same regardless of the underlying storage - simple key/value pairs. Currently, we provide Offline support for all HTML5-compliant browsers, plus earlier versions of Internet Explorer (6 and 7). The amount of storage available is dictated by the browser, and varies from approximately 500KB to approximately 5MB.
Constructor and Description |
---|
Offline() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Object |
get(java.lang.String key)
Returns the value mapped to the passed-in key from browser-local storage, or null if no such key exists.
|
static void |
goOffline()
Explicitly sets this session into offline mode.
|
static void |
goOnline()
Explicitly sets this session into online mode.
|
static java.lang.Boolean |
isOffline()
Returns true if the current browser session is offline (ie, not connected to a network).
|
static void |
put(java.lang.String key,
java.lang.Object value)
Stores the passed-in value in browser-local storage, mapped to the passed-in key.
|
static void |
put(java.lang.String key,
java.lang.Object value,
boolean recycleEntries)
Stores the passed-in value in browser-local storage, mapped to the passed-in key.
|
static void |
remove(java.lang.String key)
Removes the key/value pair mapped by the passed-in key from browser-local storage
|
static void |
useNativeOfflineDetection()
Tells the Offline system to query the browser for the current online/offline state.
|
public static void goOffline()
goOnline()
,
useNativeOfflineDetection()
public static void goOnline()
goOffline()
,
useNativeOfflineDetection()
public static java.lang.Boolean isOffline()
Offline.goOffline
and Offline.goOnline
), the explicitly-set state will be returned. Otherwise, the
offline state as reported by the browser will be returned. See useNativeOfflineDetection
for important notes on browser
detection of offline state.goOffline()
,
goOnline()
,
useNativeOfflineDetection()
public static void remove(java.lang.String key)
key
- The key to removeput(java.lang.String, java.lang.Object)
,
get(java.lang.String)
public static void useNativeOfflineDetection()
Offline.goOnline
or Offline.goOffline
. It is important to note that browsers vary
quite considerably in their ability to detect that they are offline. Many older browsers simply can't do it; HTML5
browsers expose the navigator.onLine
property, but each browser's implementation is different. Some
browsers have a manual "Work Offline" mode which allows the user to make the decision, and Smart GWT provides an
equivalent mechanism with the goOffline
and goOnline
methods. Generally speaking, these
methods are more reliable than allowing the browser to decide whether your application is offline.
goOnline()
,
goOffline()
public static java.lang.Object get(java.lang.String key)
key
- The key to retrieve a value forput(java.lang.String, java.lang.Object)
public static void put(java.lang.String key, java.lang.Object value)
recycleEntries
parameter. Note that limitations in the
underlying storage engines mean that only primitive values - Strings, numbers and booleans - can be stored. If you
wish to store an Array or Object, you will have to serialize it to JSON first, and then eval
it after
retrieval to turn it back into an object.
Note: This method throws an exception if it could not store the value (either because storage is full and recycleEntries was false, or because the value to store is simply too large)
key
- The key to use when storing the valuevalue
- The value to storepublic static void put(java.lang.String key, java.lang.Object value, boolean recycleEntries)
recycleEntries
parameter. Note that limitations in the
underlying storage engines mean that only primitive values - Strings, numbers and booleans - can be stored. If you
wish to store an Array or Object, you will have to serialize it to JSON first, and then eval
it after
retrieval to turn it back into an object.
Note: This method throws an exception if it could not store the value (either because storage is full and recycleEntries was false, or because the value to store is simply too large)
key
- The key to use when storing the valuevalue
- The value to storerecycleEntries
- If false, suppresses the default behavior of repeatedly discarding the oldest entry if
there is insufficient space to store the valueget(java.lang.String)