cacheous
v1.0.1
Published
1. _You like to ensure your data is clear and fully valid._ Schemas provide a quick way to provide validation for your data.
Downloads
11
Readme
Cacheous
A small wrapper that adds extra functionality to Keyv.
Assumptions:
You like to ensure your data is clear and fully valid. Schemas provide a quick way to provide validation for your data.
You like your data fast, but also safe. Keeping data inside an in memory cache quickly allows applications to respond to requests, and using a persistent data store keeps it safe across multiple instances.
Creating the Schema
To Create a Schema for Cacheous, use the schm
package from npm to define your schema as you would in Mongoose. Then the schema provided in the constructor.
Please see the documentation for diegohaz/schm
for how to define or extend your shcema.
Constructor Sample
cosnt Cacheous = require('cacheous');
cosnt ObjectSchema = require('./schema');
const ObjectCache = new Cacheous({
name: 'Objects',
storeURI: 'connectionstring for supported data stores',
schema: ObjectSchema
});
Api Reference
getIdList(): Promise<Array<String>>
Returns the list of ID's in the model set.
getById(id: String): Promise<Model>
Returns a Model Object that is at the specified ID.
where(filter: Function): Promise<Array<Model>>
Accepts a lambda to filter the objects in the store, and returns an array of objects for which the lambda is true.
insert(m: Model): Promise<Model>
Accepts an object of the model, validates it against the schema, and inserts into the cache.
destroy(id: String): Promise<Boolean>
Accepts an ID, and removes it from the cache.