Skip to content
pixi-silk
GitHub repository
Class

LayoutCache

import { LayoutCache } from 'pixi-silk/i18n';

A least-recently-used cache of laid out messages with a memory budget (brief sec. 8). Messages that show the same variant, values, size and width share one layout. Entries are immutable: a message that updates a slot in place clones its layout first (cloneLayout).

Constructors#

Constructor#

new LayoutCache(budget?: number): LayoutCache;

Parameters#

ParameterType
budgetnumber

Returns#

LayoutCache

Properties#

PropertyTypeDefault valueDescriptionDefined in
budgetnumberundefinedLargest total size in bytes, estimated from the instance data.packages/pixi-silk/src/i18n/cache.ts:10
hitsnumber0Lookups that found a layout.packages/pixi-silk/src/i18n/cache.ts:12
missesnumber0Lookups that did not.packages/pixi-silk/src/i18n/cache.ts:14

Accessors#

bytes#

Get Signature#

get bytes(): number;

Estimated bytes in use.

Returns

number


size#

Get Signature#

get size(): number;

Entries in the cache.

Returns

number

Methods#

clear()#

clear(): void;

Empties the cache.

Returns#

void


get()#

get(key: string): MessageLayout | undefined;

The layout for a key, marked as recently used, or undefined.

Parameters#

ParameterType
keystring

Returns#

MessageLayout | undefined


set()#

set(key: string, layout: MessageLayout): void;

Stores a layout and evicts the least recently used ones past the budget.

Parameters#

ParameterType
keystring
layoutMessageLayout

Returns#

void