Skip to content

Variable: buildCacherOptions ​

const buildCacherOptions: ComponentOptionsBuilder<CacherOptions>

Build the component options of a Cacher, to register it in the components of an application (or a module) under the name of your choice. The options are validated when the component is created, not here.

Param ​

options

The cache options: its stores, its default TTL, its refresh and write behavior. Without options, one in-memory store whose entries never expire.

Returns ​

The component options ({class: Cacher, ...options}).

Example ​

typescript
import {Application} from 'lakutata'
import {buildCacherOptions, type Cacher} from 'lakutata/com/cacher'

Application
    .run(() => ({
        id: 'cache.app',
        name: 'Cache',
        components: {
            //An in-memory cache whose entries expire after one minute
            cache: buildCacherOptions({ttl: 60000})
        }
    }))
    .onLaunched(async (app: Application): Promise<void> => {
        const cache: Cacher = await app.getObject('cache')
        await cache.set('greeting', 'Hello')
        console.log(await cache.get<string>('greeting')) //Hello
    })

Released under the MIT License.