Cache

Kind: global class
Properties

NameTypeDescription
stringcacheKeyA unique identifier for the Cache instance.
stringentryKeyThe property that defines the cache entry
numberlifetimeThe entry's lifetime in milliseconds
anyoriginalAn object based on which the cache's validation can be set

new Cache()

A simple key-value cache. Built to store typed and structured data. Qache combines simplicity and security - it clones all data and stores them instead of keeping their references in memory.

Example

const cache = new Cache<{
  id: string;
  firstName: string;
  secondName: string;
}>({
  cacheKey: 'default',
  entryKey: 'id',
  lifetime: 1000 * 60 * 5,
});
1
2
3
4
5
6
7
8
9

cache.set(key, value, options)

Adds an entry to the cache.

Kind: instance method of Cache

ParamDescription
keyIdentifier of the cache entry
valueValue of the cache entry
optionsCustom options for this cache entry

Example

cache.set('/users/1', {
 id: '1',
 firstName: 'John',
 secondName: 'Doe',
})
1
2
3
4
5

cache.get(key) ⇒ T | Array.<T>

Get a value from the cache.

Kind: instance method of Cache
Returns: T | Array.<T> - The value of the cache entry

ParamDescription
keyIdentifier of the cache entry

Example

const user = cache.get('/users/1');
console.log(user);
// Prints
// {
//  id: '1',
//  firstName: 'John',
//  secondName: 'Doe',
// }
1
2
3
4
5
6
7
8

cache.del(key) ⇒ boolean

Deletes a single entry from the cache

Kind: instance method of Cache
Returns: boolean - Whether the entry was deleted

ParamDescription
keyIdentifier of the cache entry

Example

cache.del('/users/1');
// Returns true
1
2

cache.stats() ⇒ CacheStats

Get details about the cache instance

Kind: instance method of Cache
Returns: CacheStats - A list of details about the current cache instance

cache.flush()

Resets the cache instance. Does not reset schemata and datatype.

Kind: instance method of Cache

Validator

Kind: global class
Properties

NameTypeDescription
SchemaschemaA schema object
ValidationMethodvalidatequick or deep

new Validator()

Creates minimal object-validation schemata from primitive and complex types. There are two kinds of validation: quick and deep. - quick should be used when objects look exactly alike, including their property structure - deep should be used when objects are alike structurally, but their properties's indexes differ.

validator.validate(data)

Validates an item against the currently active schema

Kind: instance method of Validator

ParamDescription
dataThe item to validate

validator.validateList(data)

Validates an array of items against the currently active schema

Kind: instance method of Validator

ParamDescription
dataAn array of items to validate

validator.getSchema()

Get the currently active schema of this validator instance

Kind: instance method of Validator