Adds schema caching capabilities (5s by default) (#2286)

* Adds schema caching capabilities (off by default)

* Use InMemoryCacheAdapter

* Uses proper adapter to generate a cache

* Fix bugs when running disabled cache

* nits

* nits

* Use options object instead of boolean

* Imrpove concurrency of loadSchema

* Adds testing with SCHEMA_CACHE_ON

* Use CacheController instead of generator

- Makes caching SchemaCache use a generated prefix
- Makes clearing the SchemaCache clear only the cached schema keys
- Enable cache by default (ttl 5s)
This commit is contained in:
Florent Vilmart
2016-07-23 06:23:59 +02:00
committed by Drew
parent 66c4b98b55
commit 09bd9e3b2c
14 changed files with 205 additions and 47 deletions

View File

@@ -15,15 +15,15 @@ function classNameMismatchResponse(bodyClass, pathClass) {
}
function getAllSchemas(req) {
return req.config.database.loadSchema()
.then(schemaController => schemaController.getAllClasses())
return req.config.database.loadSchema({ clearCache: true})
.then(schemaController => schemaController.getAllClasses(true))
.then(schemas => ({ response: { results: schemas } }));
}
function getOneSchema(req) {
const className = req.params.className;
return req.config.database.loadSchema()
.then(schemaController => schemaController.getOneSchema(className))
return req.config.database.loadSchema({ clearCache: true})
.then(schemaController => schemaController.getOneSchema(className, true))
.then(schema => ({ response: schema }))
.catch(error => {
if (error === undefined) {
@@ -46,7 +46,7 @@ function createSchema(req) {
throw new Parse.Error(135, `POST ${req.path} needs a class name.`);
}
return req.config.database.loadSchema()
return req.config.database.loadSchema({ clearCache: true})
.then(schema => schema.addClassIfNotExists(className, req.body.fields, req.body.classLevelPermissions))
.then(schema => ({ response: schema }));
}
@@ -59,7 +59,7 @@ function modifySchema(req) {
let submittedFields = req.body.fields || {};
let className = req.params.className;
return req.config.database.loadSchema()
return req.config.database.loadSchema({ clearCache: true})
.then(schema => schema.updateClass(className, submittedFields, req.body.classLevelPermissions, req.config.database))
.then(result => ({response: result}));
}