Interface JStorageStatic

Index

Methods

Methods

public currentBackend(): Storage

Which backend is currently in use?

Returns

Storage

Backend name

public deleteKey(key: string): boolean

Deletes a key from cache.

Parameters

  • key: string
    • Key to delete.

Returns

boolean

true if key existed or false if it didn't

public flush(): boolean

Deletes everything in cache.

Returns

boolean

Always true

public get(key: string, defaultIfNotFound?: TValue): TValue

Looks up a key in cache

Parameters

  • key: string
    • Key to look up.
  • defaultIfNotFound?: TValue optional
    • Default value to return, if key didn't exist.

Returns

TValue

the key value, default value or null

public getTTL(key: string): number

Gets remaining TTL (in milliseconds) for a key or 0 when no TTL has been set

Parameters

  • key: string

    Key to check

Returns

number

Remaining TTL in milliseconds

public index(): Array<string>

Returns an index of all used keys as an array ['key1', 'key2',..'keyN']

Returns

Array<string>

Used keys

public listenKeyChange(key: string, callback: (key: string, value: any) => void)

Register change listeners

Parameters

  • key: string

    Key name

  • callback: (key: string, value: any) => void

    Function to run when the key changes

public listenKeyChange(key: string, callback: (key: string, value: TValue) => void)

Register change listeners

Parameters

  • key: string

    Key name

  • callback: (key: string, value: TValue) => void

    Function to run when the key changes

public publish(channel: string, payload: any)

Publish data to an event stream

Parameters

  • channel: string

    Channel name

  • payload: any

    Payload to deliver

public reInit()

Reloads the data from browser storage

public set(key: string, value: TValue, options?: JStorageOptions): TValue

Sets a key's value.

Parameters

  • key: string

    Key to set. If this value is not set or not a string an exception is raised.

  • value: TValue

    Value to set. This can be any value that is JSON compatible (Numbers, Strings, Objects etc.).

  • options?: JStorageOptions optional

Returns

TValue

the used value

public setTTL(key: string, ttl: number): boolean

Sets a TTL for a key, or remove it if ttl value is 0 or below

Parameters

  • key: string
    • key to set the TTL for
  • ttl: number
    • TTL timeout in milliseconds

Returns

boolean

true if key existed or false if it didn't

public stopListening(key: string, callback?: Function)

Remove change listeners

Parameters

  • key: string

    Key name to unregister listeners against

  • callback?: Function optional

public storageAvailable(): boolean

Test if storage is available

Returns

boolean

True if storage can be used

public storageObj(): JStorageReadonlyStore

Returns a read-only copy of _storage

Returns

JStorageReadonlyStore

Read-only copy of _storage

public storageSize(): number

How much space in bytes does the storage take?

Returns

number

Storage size in chars (not the same as in bytes, since some chars may take several bytes)

public subscribe(channel: string, callback: (channel: string, value: any) => void)

Subscribe to a Publish/Subscribe event stream

Parameters

  • channel: string

    Channel name

  • callback: (channel: string, value: any) => void

    Function to run when the something is published to the channel

public subscribe(channel: string, callback: (channel: string, value: TValue) => void)

Subscribe to a Publish/Subscribe event stream

Parameters

  • channel: string

    Channel name

  • callback: (channel: string, value: TValue) => void

    Function to run when the something is published to the channel