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

@@ -55,6 +55,7 @@ import { UsersRouter } from './Routers/UsersRouter';
import { PurgeRouter } from './Routers/PurgeRouter';
import DatabaseController from './Controllers/DatabaseController';
import SchemaCache from './Controllers/SchemaCache';
const SchemaController = require('./Controllers/SchemaController');
import ParsePushAdapter from 'parse-server-push-adapter';
import MongoStorageAdapter from './Adapters/Storage/Mongo/MongoStorageAdapter';
@@ -139,6 +140,7 @@ class ParseServer {
expireInactiveSessions = true,
verbose = false,
revokeSessionOnPasswordReset = true,
schemaCacheTTL = 5, // cache for 5s
__indexBuildCompletionCallbackForTests = () => {},
}) {
// Initialize the node client SDK automatically
@@ -197,7 +199,7 @@ class ParseServer {
const userController = new UserController(emailControllerAdapter, appId, { verifyUserEmails });
const liveQueryController = new LiveQueryController(liveQuery);
const cacheController = new CacheController(cacheControllerAdapter, appId);
const databaseController = new DatabaseController(databaseAdapter);
const databaseController = new DatabaseController(databaseAdapter, new SchemaCache(cacheController, schemaCacheTTL));
const hooksController = new HooksController(appId, databaseController, webhookKey);
const analyticsController = new AnalyticsController(analyticsControllerAdapter);
@@ -254,6 +256,7 @@ class ParseServer {
jsonLogs,
revokeSessionOnPasswordReset,
databaseController,
schemaCacheTTL
});
// To maintain compatibility. TODO: Remove in some version that breaks backwards compatability