Skip to content

Latest commit

 

History

History
112 lines (87 loc) · 4.3 KB

DOC.md

File metadata and controls

112 lines (87 loc) · 4.3 KB

Cache

Kind: global class

new Cache([options])

Creates a new Cache.

Param Type Default Description
[options] object Possible options to use
[options.limit] number no limit Maximum size of the cache.
[options.storage] object internal storage Replace the storage engine (localStorage, sessionStorage or any object).
[options.keyPrefix] string "cache#{index}:" If options.storage is set, namespace all storage keys to avoid conflicts. of data items stored in the storage object.
[options.expires] date | timestamp Set an expiry date. After this date, all items will be removed.
[options.maxAge] maxAge Set the time in milliseconds for when the current data items will be removed

cache.length : number

Returns an integer representing the number of data items stored

Kind: instance property of Cache

cache.hasKey(key) ⇒ boolean

Return true if the given key is present in storage

Kind: instance method of Cache

Param Type
key string

cache.setItem(key, item, [options]) ⇒ Cache

When passed a key name and value, will add that key to the storage, or update that key's value if it already exists (note that, in this case, the key order will be updated as well). Purge the storage if the number of items exceed the limit.

Kind: instance method of Cache

Param Type Description
key string
item *
[options] object Possible options to use
[options.expires] date | timestamp Set an expiry date for this item. After this date, the item will be removed.
[options.maxAge] maxAge Set the time in milliseconds for when this item will be removed.

cache.getItem(key, [defaultValue]) ⇒ *

When passed a key name, will return that key's value. If no value is found, return undefined or the given defaultValue.

Kind: instance method of Cache
Returns: * - item - /!\ The type of item will be a string if the storage is localStorage or sessionStorage.

Param Type
key string
[defaultValue] *

cache.removeItem(key) ⇒ Cache

When passed a key name, will remove that key from the storage.

Kind: instance method of Cache

Param Type
key string

cache.setLimit(limit) ⇒ Cache

Set the maximum size of the storage. Remove the oldest elements if the storage limit is reached.

Kind: instance method of Cache

Param Type Description
limit number A positive number

cache.clear() ⇒ Cache

Empty all keys out of the storage.

Kind: instance method of Cache

cache.key(n) ⇒ string

Return the name of the nth key in the storage.

Kind: instance method of Cache

Param Type
n number