You can tweak several details of the behavior of this class, check out Props for more information.
By default, no tweaking is required.
Usage:
const entries: [string, any][] = [];
for (const [k, v] of storage) {
entries.push([k, v]);
}
entries; // equals: [[ 'key1', '1' ], [ 'key2', '2' ], ... ]
iterator over key/value pairs
calls localStorage.clear()
and returns true if it worked – otherwise false.
Deletes key from local storage
Throws an error only if you try to delete the reserved key to record recent entries.
Delete a value or nested object from within a nested object at the given path. It returns the deleted object.
Delete all keys with the given prefix
remove a key from the recently used list
Each value in localStorage is a string. For specific prefixes, this deserializes the value. As a fallback, it optionally tries to use JSON.parse. If everything fails, the plain string value is returned.
Get data from a nested object
the number of recent keys tracked
Keys of last recently used entries. The most recent one comes first!
Return all keys in local storage, optionally sorted.
Returns true, if we can store something in local storage at all.
avoid trimming more useful entries, we keep an array of recently modified keys
specific types are serialized with a prefix, while plain strings are stored as they are.
Wrapper around localStorage, so we can safely touch it without raising an exception if it is banned (like in some browser modes) or doesn't exist.
Set data in nested objects and merge with existing values
number of items stored in the local storage – not counting the "recent key" itself
Trim the local storage in case it is too big. In case there is an error upon storing a value, we assume we hit the quota limit. Try a couple of times to delete some entries and saving the key/value pair.
Returns true, if we can store something in local storage at all. This is used for testing and during initialization.
Generated using TypeDoc
LocalStorageLRU Copyright 2022 SageMath, Inc. Licensed under the Apache License, Version 2.0