Cache

Record

NameTypeDescription

expired

boolean

Was cache expired or not

value

any

Cache value

Cache class

Cache.file

Path to the file where the cache should be stored

Cache.get(name)

import { Cache, promisify } from '@empathize/framework';

promisify(async () => {
    let record = await Cache.get('not_existing_record');
    
    // Record doesn't exist
    console.log(record === null ? 'Record doesn\'t exist' : 'Record exist');
    
    record = await Cache.get('existing_record');
    
    // Record exists
    console.log(record === null ? 'Record doesn\'t exist' : 'Record exists');
});

Cache.set(name, value, ttl)

import { Cache } from '@empathize/framework';

// Will be cached forever
Cache.set('record_1', 'Hello, World!');

// Will be cached for 24 hours
Cache.set('record_2', 'Hello, World!', 24 * 3600);

Last updated