diff --git a/classes/LocalStorageLRU.html b/classes/LocalStorageLRU.html index 4f95186..fd5fa87 100644 --- a/classes/LocalStorageLRU.html +++ b/classes/LocalStorageLRU.html @@ -2,57 +2,57 @@

LocalStorageLRU Copyright 2022 SageMath, Inc. Licensed under the Apache License, Version 2.0

-

Hierarchy

Index

Constructors

Hierarchy

Index

Constructors

Properties

delimiter: string
deserializer: ((ser: string) => any)

Type declaration

    • (ser: string): any
    • Parameters

      • ser: string

      Returns any

isCandidate?: ((key: string, recent: string[]) => boolean)

Type declaration

    • (key: string, recent: string[]): boolean
    • Parameters

      • key: string
      • recent: string[]

      Returns boolean

ls: Storage
maxSize: number
parseExistingJSON: boolean
recentKey: string
serializer: ((data: any) => string)

Type declaration

    • (data: any): string
    • Parameters

      • data: any

      Returns string

typePrefixDelimiter: string
typePrefixes: TypePrefixes

Methods

  • [iterator](): IterableIterator<[string, string | object]>

Properties

delimiter: string
deserializer: ((ser: string) => any)

Type declaration

    • (ser: string): any
    • Parameters

      • ser: string

      Returns any

isCandidate?: ((key: string, recent: string[]) => boolean)

Type declaration

    • (key: string, recent: string[]): boolean
    • Parameters

      • key: string
      • recent: string[]

      Returns boolean

ls: Storage
maxSize: number
parseExistingJSON: boolean
recentKey: string
serializer: ((data: any) => string)

Type declaration

    • (data: any): string
    • Parameters

      • data: any

      Returns string

typePrefixDelimiter: string
typePrefixes: TypePrefixes

Methods

  • [iterator](): IterableIterator<[string, string | object]>
  • Usage:

    const entries: [string, any][] = [];
    for (const [k, v] of storage) {
    entries.push([k, v]);
    }
    entries; // equals: [[ 'key1', '1' ], [ 'key2', '2' ], ... ]

    Returns IterableIterator<[string, string | object]>

    iterator over key/value pairs

    -
  • checkPrefixes(): void
  • clear(): boolean
  • checkPrefixes(): void
  • clear(): boolean
  • calls localStorage.clear() and returns true if it worked – otherwise false.

    -

    Returns boolean

  • delete(key: string): void
  • delete(key: string): void
  • Deletes key from local storage

    Throws an error only if you try to delete the reserved key to record recent entries.

    -

    Parameters

    • key: string

    Returns void

  • deleteData(key: string, pathParam: string | string[]): any
  • deleteData(key: string, pathParam: string | string[]): any
  • Delete a value or nested object from within a nested object at the given path. It returns the deleted object.

    -

    Parameters

    • key: string
    • pathParam: string | string[]

    Returns any

  • deletePrefix(prefix: string): void
  • deletePrefix(prefix: string): void
  • deleteUsage(key: string): void
  • deleteUsage(key: string): void
  • deserialize(ser: null | string): any
  • deserialize(ser: null | string): any
  • 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.

    -

    Parameters

    • ser: null | string

    Returns any

  • get(key: string): null | string | object
  • getData(key: string, pathParam: string | string[]): any
  • get(key: string): null | string | object
  • getData(key: string, pathParam: string | string[]): any
  • Get data from a nested object

    -

    Parameters

    • key: string
    • pathParam: string | string[]

    Returns any

  • getLocalStorage(): Storage
  • getMaxSize(): number
  • getLocalStorage(): Storage
  • getMaxSize(): number
  • getRecent(): string[]
  • getRecent(): string[]
  • Keys of last recently used entries. The most recent one comes first!

    -

    Returns string[]

  • getRecentKey(): string
  • has(key: string): boolean
  • initLocalStorage(props?: Props): Storage
  • keys(sorted?: boolean): string[]
  • getRecentKey(): string
  • has(key: string): boolean
  • initLocalStorage(props?: Props): Storage
  • keys(sorted?: boolean): string[]
  • Return all keys in local storage, optionally sorted.

    -

    Parameters

    • sorted: boolean = false

    Returns string[]

  • localStorageIsAvailable(): boolean
  • localStorageIsAvailable(): boolean
  • recordUsage(key: string): void
  • recordUsage(key: string): void
  • avoid trimming more useful entries, we keep an array of recently modified keys

    -

    Parameters

    • key: string

    Returns void

  • serialize(val: unknown): string
  • serialize(val: unknown): string
  • specific types are serialized with a prefix, while plain strings are stored as they are.

    -

    Parameters

    • val: unknown

    Returns string

  • set(key: string, val: unknown): void
  • set(key: string, val: unknown): void
  • 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.

    -

    Parameters

    • key: string
    • val: unknown

    Returns void

  • setData(key: string, pathParam: string | string[], value: any): void
  • setData(key: string, pathParam: string | string[], value: any): void
  • Set data in nested objects and merge with existing values

    -

    Parameters

    • key: string
    • pathParam: string | string[]
    • value: any

    Returns void

  • size(): number
  • size(): number
  • number of items stored in the local storage – not counting the "recent key" itself

    -

    Returns number

  • trim(key: string, val: string): boolean
  • trim(key: string, val: string): boolean
  • 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.

    -

    Parameters

    • key: string
    • val: string

    Returns boolean

  • trimOldEntries(): void
  • testLocalStorage(ls: { getItem: any; removeItem: any; setItem: any }): boolean
  • trimOldEntries(): void
  • testLocalStorage(ls: { getItem: any; removeItem: any; setItem: any }): boolean
  • Returns true, if we can store something in local storage at all. This is used for testing and during initialization.

    static

    Parameters

    • ls: { getItem: any; removeItem: any; setItem: any }
      -
      • getItem:function
        • getItem(key: string): null | string
      • removeItem:function
        • removeItem(k: string): void
      • setItem:function
        • setItem(k: string, v: string): void

    Returns boolean

Generated using TypeDoc

\ No newline at end of file +

Returns boolean

Generated using TypeDoc

\ No newline at end of file diff --git a/interfaces/Props.html b/interfaces/Props.html index b1f9ad9..341a76e 100644 --- a/interfaces/Props.html +++ b/interfaces/Props.html @@ -1,29 +1,29 @@ -Props | @cocalc/local-storage-lru
Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Props

Index

Properties

delimiter?: string
+Props | @cocalc/local-storage-lru
Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Props

Index

Properties

delimiter?: string

the delimiter used to separate keys in the recent list

default

"\0"

-
fallback?: boolean
+
fallback?: boolean

if true, use a memory-backed fallback store, if a check test of localStorage fails

-
localStorage?: Storage
+
localStorage?: Storage

only used for testing

-
maxSize?: number
+
maxSize?: number

how many most recently used keys are tracked – i.e. the number of tracked recently used objects.

default

64

-
parseExistingJSON?: boolean
+
parseExistingJSON?: boolean

if true, attempt to parse already existing JSON in localStorage

-
recentKey?: string
+
recentKey?: string

the key used to store the list of recently used keys

-
typePrefixDelimiter?: string
+
typePrefixDelimiter?: string

a common string delimiting the type prefix and the value, could be an empty string.

default

"\0"

-
typePrefixes?: TypePrefixes
+
typePrefixes?: TypePrefixes

custom type prefixes

-

Methods

  • deserializer(ser: string): any

Methods

  • deserializer(ser: string): any
  • corresponding to serializer custom de-serializer

    default

    JSON.parse

    -

    Parameters

    • ser: string

    Returns any

  • isCandidate(key: string, recent: string[]): boolean
  • +

    Parameters

    • ser: string

    Returns any

  • isCandidate(key: string, recent: string[]): boolean
  • A function preventing certain keys from being removed – i.e. only if it returns true, that key is a candidate for removal. Use it to prevent keys from being removed if they are "more important" than others.

    -

    Parameters

    • key: string
    • recent: string[]

    Returns boolean

  • serializer(data: any): string
  • +

    Parameters

    • key: string
    • recent: string[]

    Returns boolean

  • serializer(data: any): string
  • bring your own custom object serializer – must have corresponding a counterpart deserializer

    default

    JSON.stringify

    Parameters

    • data: any

    Returns string

Legend

  • Property
  • Method
  • Constructor
  • Method
  • Private property
  • Private method
  • Static method

Settings

Theme

Generated using TypeDoc

\ No newline at end of file diff --git a/interfaces/TypePrefixes.html b/interfaces/TypePrefixes.html index 61d66a2..b51dbce 100644 --- a/interfaces/TypePrefixes.html +++ b/interfaces/TypePrefixes.html @@ -1,3 +1,3 @@ TypePrefixes | @cocalc/local-storage-lru
Options
All
  • Public
  • Public/Protected
  • All
Menu

specify all prefixes as strings, they must be distinct from each other. pure "string" objects are stored without a prefix.

-

Hierarchy

  • TypePrefixes

Index

Properties

bigint: string
date: string
float: string
int: string
object: string

Legend

  • Property
  • Method
  • Constructor
  • Method
  • Private property
  • Private method
  • Static method

Settings

Theme

Generated using TypeDoc

\ No newline at end of file +

Hierarchy

  • TypePrefixes

Index

Properties

bigint: string
date: string
float: string
int: string
object: string

Generated using TypeDoc

\ No newline at end of file