labs.storage.BoundedCollectableStorage Extends goog.storage.CollectableStorage
Provides a storage with bounded number of elements, expiring keys and a collection method.

Inheritance

Constructor

goog.labs.storage.BoundedCollectableStorage(mechanismmaxItems)

Parameters

mechanism : !goog.storage.mechanism.IterableMechanism
The underlying storage mechanism.
maxItems : number
Maximum number of items in storage.

Instance Methods

Public Protected Private
collect(opt_strict)
Cleans up the storage by removing expired keys.
Arguments:
opt_strict : boolean=
Also remove invalid keys.
code »
collectOversize(opt_skipExpiredopt_strict)
Ensures that we keep only maxItems number of items in a local storage.
Arguments:
opt_skipExpired : boolean=
skip removing expired items first.
opt_strict : boolean=
Also remove invalid keys.
code »
collectOversize_(keysmaxSize) !Array.<string>
Keeps the number of items in storage under maxItems. Removes elements in the order of creation.
Arguments:
keys : !Array.<string>
a list of keys in order of creation.
maxSize : number
a number of items to keep.
Returns: !Array.<string>  keys left after removing oversize data.
code »
getKeys_(rebuild) !Array.<string>
Gets key list from a local storage. If an item does not exist, may recreate it.
Arguments:
rebuild : boolean
Whether to rebuild a index if no index item exists.
Returns: !Array.<string>  a list of keys if index exist, otherwise undefined.
code »
rebuildIndex_() !Array.<string>
Recreates a list of keys in order of creation.
Returns: !Array.<string>  a list of unexpired keys.
code »
remove(key)
Remove an item from the data storage.
Arguments:
key : string
The key to remove.
code »
set(keyvalueopt_expiration)
Set an item in the storage.
Arguments:
key : string
The key to set.
value : *
The value to serialize to a string and save.
opt_expiration : number=
The number of miliseconds since epoch (as in goog.now()) when the value is to expire. If the expiration time is not provided, the value will persist as long as possible.
code »
setKeys_(keys)
Saves a list of keys in a local storage.
Arguments:
keys : Array.<string>
a list of keys to save.
code »
collect(opt_strict)
Cleans up the storage by removing expired keys.
Arguments:
opt_strict : boolean=
Also remove invalid keys.
code »
collectInternal(keysopt_strict) !Array.<string>
Cleans up the storage by removing expired keys.
Arguments:
keys : Array.<string>
List of all keys.
opt_strict : boolean=
Also remove invalid keys.
Returns: !Array.<string>  a list of expired keys.
code »
getExpiredKeys_(keysopt_strict) !Array.<string>
Iterate over keys and returns those that expired.
Arguments:
keys : goog.iter.Iterable
keys to iterate over.
opt_strict : boolean=
Also return invalid keys.
Returns: !Array.<string>  Keys of values that expired.
code »
getWrapper(keyopt_expired) ⇒ (!Object | undefined)
Get an item wrapper (the item and its metadata) from the storage.
Arguments:
key : string
The key to get.
opt_expired : boolean=
If true, return expired wrappers as well.
Returns: (!Object | undefined)  The wrapper, or undefined if not found.
code »
set(keyvalueopt_expiration)
Set an item in the storage.
Arguments:
key : string
The key to set.
value : *
The value to serialize to a string and save.
opt_expiration : number=
The number of miliseconds since epoch (as in goog.now()) when the value is to expire. If the expiration time is not provided, the value will persist as long as possible.
code »
get()
No description.
code »
getWrapper(key) ⇒ (!Object | undefined)
Get an item wrapper (the item and its metadata) from the storage. WARNING: This returns an Object, which once used to be goog.storage.RichStorage.Wrapper. This is due to the fact that deserialized objects lose type information and it is hard to do proper typecasting in JavaScript. Be sure you know what you are doing when using the returned value.
Arguments:
key : string
The key to get.
Returns: (!Object | undefined)  The wrapper, or undefined if not found.
code »
set()
No description.
code »
get(key) *
Gets an item from the data storage.
Arguments:
key : string
The key to get.
Returns: *  Deserialized value or undefined if not found.
code »
remove(key)
Removes an item from the data storage.
Arguments:
key : string
The key to remove.
code »
set(keyvalue)
Sets an item in the data storage.
Arguments:
key : string
The key to set.
value : *
The value to serialize to a string and save.
code »

Instance Properties

constructor :
No description.
Code »
maxItems_ :
A maximum number of items that should be stored.
Code »
constructor :
No description.
Code »
constructor :
No description.
Code »
constructor :
No description.
Code »
The mechanism used to persist key-value pairs.
Code »

Static Methods

goog.labs.storage.BoundedCollectableStorage.removeSubsequence_(keyskeysToRemove) !Array.<string>
Remove subsequence from a sequence.
Arguments:
keys : !Array.<string>
is a sequence.
keysToRemove : !Array.<string>
subsequence of keys, the order must be kept.
Returns: !Array.<string>  a keys sequence after removing keysToRemove.
code »

Static Properties

goog.labs.storage.BoundedCollectableStorage.KEY_LIST_KEY_ :
An item key used to store a list of keys.
Code »
goog.labs.storage.BoundedCollectableStorage.superClass_ :
No description.
Code »

Package labs.storage

Package Reference