public final class StorageExt extends Object
You can obtain a Storage by either invoking
getLocalStorage() or
getSessionStorage().
If Web Storage is NOT supported in the browser, these methods return
null.
Note: Storage events into other windows are not supported.
This may not be supported on all browsers.
| Modifier and Type | Method and Description |
|---|---|
com.google.web.bindery.event.shared.HandlerRegistration |
addStorageChangeHandler(StorageChangeEvent.Handler handler)
Registers an event handler for
StorageChangeEvent |
void |
clear()
Removes all items in the Storage, and its cache if activated
|
void |
clearCache()
Clear all cached serialized object from configured
StorageCache |
<T> boolean |
containsKey(StorageKey<T> key)
Test if this storage contains a value for the specified key.
|
<T> T |
get(StorageKey<T> key)
Returns the value in the Storage associated with the specified key,
or
null if this Storage contains no mapping for the key. |
static StorageExt |
getLocalStorage()
Returns a Local Storage.
|
static StorageExt |
getSessionStorage()
Returns a Session Storage.
|
String |
getString(String key)
Get directly the stored string value associated with the specified key.
|
String |
key(int index)
Returns the key at the specified index.
|
<T> void |
put(StorageKey<T> key,
T value)
Store the specified value with the specified key in this storage.
|
<T extends Serializable> |
remove(StorageKey<T> key)
Removes the record for the specified key from this storage if present.
|
void |
setEventLevel(StorageChangeEvent.Level eventLevel)
Set Event Level.
|
int |
size()
Returns the number of items in this Storage.
|
public static StorageExt getLocalStorage()
null if Web Storage is NOT supported.public static StorageExt getSessionStorage()
null if Web Storage is NOT supported.public com.google.web.bindery.event.shared.HandlerRegistration addStorageChangeHandler(StorageChangeEvent.Handler handler)
StorageChangeEventhandler - an event handler instanceHandlerRegistration used to remove this handlerpublic void clear()
public void clearCache()
StorageCachepublic <T> boolean containsKey(StorageKey<T> key)
StorageKeyFactory is preferred to get a StorageKey instance for primitive types.
T - the type of stored valuekey - the key whose presence in this storage is to be testedpublic <T> T get(StorageKey<T> key) throws com.google.gwt.user.client.rpc.SerializationException
null if this Storage contains no mapping for the key.
Note : Deserialization will be performed to return a correct value type.
StorageKeyFactory is preferred to get a StorageKey instance for primitive types.
T - the type of stored valuekey - the key to a value in the Storagecom.google.gwt.user.client.rpc.SerializationExceptionpublic String getString(String key)
Note : No deserialization will be performed
key - the key to a value in the Storagepublic String key(int index)
index - the index of the keypublic <T> void put(StorageKey<T> key, T value) throws com.google.gwt.user.client.rpc.SerializationException, StorageQuotaExceededException
Note: null value is not allowed.
If the storage previously contained a mapping for the key, the old
value is replaced.
StorageKeyFactory is preferred to get a StorageKey instance for primitive types.
key - key with which the specified value is to be associatedvalue - value to be associated with the specified keycom.google.gwt.user.client.rpc.SerializationExceptionStorageQuotaExceededExceptionpublic <T extends Serializable> void remove(StorageKey<T> key)
StorageKeyFactory is preferred to get a StorageKey instance for primitive types
T - the type of stored valuekey - key whose mapping is to be removed from the mappublic void setEventLevel(StorageChangeEvent.Level eventLevel)
Note : set to StorageChangeEvent.Level.STRING,
will prevent the deserialization process in event creation,
This matters only if the old value (object value) is wanted in every storage change event.
eventLevel - the event detail levelStorageChangeEventpublic int size()
Copyright © 2018 seanchenxi.com. All rights reserved.