Edit

Share via


TokenCache class

In-memory token cache manager

Constructors

TokenCache(NodeStorage, Logger, ICachePlugin)

Properties

persistence

Methods

deserialize(string)

Deserializes JSON to in-memory cache. JSON should be in MSAL cache schema format

getAccountByHomeId(string)

Returns the signed in account matching homeAccountId. (the account object is created at the time of successful login) or null when no matching account is found

getAccountByLocalId(string)

Returns the signed in account matching localAccountId. (the account object is created at the time of successful login) or null when no matching account is found

getAllAccounts(string)

API that retrieves all accounts currently in cache to the user

getCacheSnapshot()

Gets cache snapshot in CacheKVStore format

getKVStore()

Fetches the cache key-value map

hasChanged()

Set to true if cache state has changed since last time serialize or writeToPersistence was called

overwriteCache()

Overwrites in-memory cache with persistent cache

removeAccount(AccountInfo, string)

API to remove a specific account and the relevant data from cache

serialize()

Serializes in memory cache to JSON

Constructor Details

TokenCache(NodeStorage, Logger, ICachePlugin)

new TokenCache(storage: NodeStorage, logger: Logger, cachePlugin?: ICachePlugin)

Parameters

storage

NodeStorage

logger
Logger
cachePlugin
ICachePlugin

Property Details

persistence

persistence: ICachePlugin

Property Value

Method Details

deserialize(string)

Deserializes JSON to in-memory cache. JSON should be in MSAL cache schema format

function deserialize(cache: string)

Parameters

cache

string

blob formatted cache

getAccountByHomeId(string)

Returns the signed in account matching homeAccountId. (the account object is created at the time of successful login) or null when no matching account is found

function getAccountByHomeId(homeAccountId: string): Promise<null | AccountInfo>

Parameters

homeAccountId

string

unique identifier for an account (uid.utid)

Returns

Promise<null | AccountInfo>

getAccountByLocalId(string)

Returns the signed in account matching localAccountId. (the account object is created at the time of successful login) or null when no matching account is found

function getAccountByLocalId(localAccountId: string): Promise<null | AccountInfo>

Parameters

localAccountId

string

unique identifier of an account (sub/obj when homeAccountId cannot be populated)

Returns

Promise<null | AccountInfo>

getAllAccounts(string)

API that retrieves all accounts currently in cache to the user

function getAllAccounts(correlationId?: string): Promise<AccountInfo[]>

Parameters

correlationId

string

Returns

Promise<AccountInfo[]>

getCacheSnapshot()

Gets cache snapshot in CacheKVStore format

function getCacheSnapshot(): CacheKVStore

Returns

getKVStore()

Fetches the cache key-value map

function getKVStore(): CacheKVStore

Returns

hasChanged()

Set to true if cache state has changed since last time serialize or writeToPersistence was called

function hasChanged(): boolean

Returns

boolean

overwriteCache()

Overwrites in-memory cache with persistent cache

function overwriteCache(): Promise<void>

Returns

Promise<void>

removeAccount(AccountInfo, string)

API to remove a specific account and the relevant data from cache

function removeAccount(account: AccountInfo, correlationId?: string): Promise<void>

Parameters

account
AccountInfo

AccountInfo passed by the user

correlationId

string

Returns

Promise<void>

serialize()

Serializes in memory cache to JSON

function serialize(): string

Returns

string