Home Intro Source Mebo GitHub
import LruCache from 'mebo/src/Utils/LruCache.js'
public class | source

LruCache

A cache that discards the least recently used items first.

This feature is used by the Session to store the result of cacheable actions (Action.isCacheable).

Constructor Summary

Public Constructor
public

constructor(size: number, lifespan: number)

Creates an LruCache

Member Summary

Public Members
public get

Returns the number of items held by the cache

public get

Returns the lifespan for the values held by the cache in seconds

public get

Returns the size of the cache in bytes

Method Summary

Public Methods
public

flush(key: string)

Resets the cache by flushing it

public

get(key: string, defaultValue: *): *

Returns the value from the lru cache based on the input Action.id, otherwise if the id is not found under the cache then returns undefined

public

has(key: string): boolean

Returns a boolean telling if the input key is under the cache

public

Returns a list containing the keys of the values held by the cache

public

set(key: string, value: *)

Sets a result value to the lru cache, this value is associated with the Action.id

Public Constructors

public constructor(size: number, lifespan: number) source

Creates an LruCache

Params:

NameTypeAttributeDescription
size number

Sets in bytes the maximum size of the cache

lifespan number

Lifespan in milliseconds about amount of time that an item under LRU cache should be kept alive

Public Members

public get length: number source

Returns the number of items held by the cache

public get lifespan: number source

Returns the lifespan for the values held by the cache in seconds

public get size: number source

Returns the size of the cache in bytes

Public Methods

public flush(key: string) source

Resets the cache by flushing it

Params:

NameTypeAttributeDescription
key string
  • optional

id associated with the value otherwise flushes the whole cache

public get(key: string, defaultValue: *): * source

Returns the value from the lru cache based on the input Action.id, otherwise if the id is not found under the cache then returns undefined

Params:

NameTypeAttributeDescription
key string

id associated with the value

defaultValue *
  • optional
  • default: undefined

value returned in case the key does not exist

Return:

*

public has(key: string): boolean source

Returns a boolean telling if the input key is under the cache

Params:

NameTypeAttributeDescription
key string

id associated with the value

Return:

boolean

public keys(): Array<string> source

Returns a list containing the keys of the values held by the cache

Return:

Array<string>

public set(key: string, value: *) source

Sets a result value to the lru cache, this value is associated with the Action.id

Params:

NameTypeAttributeDescription
key string

id associated with the value

value *

value that should be store by the cache