From b0ff3026aa4444bd3dd153ad7103010ae29e72fc Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Fri, 15 Jul 2016 11:28:57 -0400 Subject: [PATCH] Uses proper adapter to generate a cache --- src/Config.js | 2 +- src/Controllers/SchemaCache.js | 6 ++---- src/ParseServer.js | 9 +++++++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Config.js b/src/Config.js index 941eecb8ea..633921ee5f 100644 --- a/src/Config.js +++ b/src/Config.js @@ -36,7 +36,7 @@ export class Config { // Create a new DatabaseController per request if (cacheInfo.databaseController) { - this.database = new DatabaseController(cacheInfo.databaseController.adapter, new SchemaCache(cacheInfo.schemaCacheTTL)); + this.database = new DatabaseController(cacheInfo.databaseController.adapter, cacheInfo.createSchemaCache()); } this.serverURL = cacheInfo.serverURL; diff --git a/src/Controllers/SchemaCache.js b/src/Controllers/SchemaCache.js index f97f35e4d2..b3f6db2bc9 100644 --- a/src/Controllers/SchemaCache.js +++ b/src/Controllers/SchemaCache.js @@ -1,14 +1,12 @@ -import { InMemoryCacheAdapter } from '../Adapters/Cache/InMemoryCacheAdapter'; - const CACHED_KEYS = "__CACHED_KEYS"; const MAIN_SCHEMA = "__MAIN_SCHEMA"; const SCHEMA_CACHE_PREFIX = "__SCHEMA"; export default class SchemaCache { cache: Object; - constructor(ttl) { + constructor(adapter, ttl) { this.ttl = ttl; - this.cache = new InMemoryCacheAdapter({ ttl }); + this.cache = adapter; } getAllClasses() { diff --git a/src/ParseServer.js b/src/ParseServer.js index e4db30fa26..bdca261e60 100644 --- a/src/ParseServer.js +++ b/src/ParseServer.js @@ -186,6 +186,10 @@ class ParseServer { const emailControllerAdapter = loadAdapter(emailAdapter); const cacheControllerAdapter = loadAdapter(cacheAdapter, InMemoryCacheAdapter, {appId: appId}); + const createSchemaCache = function() { + let adapter = loadAdapter(cacheAdapter, InMemoryCacheAdapter, {appId: appId, ttl: schemaCacheTTL}); + return new SchemaCache(adapter, schemaCacheTTL); + } // We pass the options and the base class for the adatper, // Note that passing an instance would work too const filesController = new FilesController(filesControllerAdapter, appId); @@ -194,7 +198,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, new SchemaCache(schemaCacheTTL)); + const databaseController = new DatabaseController(databaseAdapter, createSchemaCache()); const hooksController = new HooksController(appId, databaseController, webhookKey); // TODO: create indexes on first creation of a _User object. Otherwise it's impossible to @@ -246,7 +250,8 @@ class ParseServer { expireInactiveSessions: expireInactiveSessions, revokeSessionOnPasswordReset, databaseController, - schemaCacheTTL + schemaCacheTTL, + createSchemaCache }); // To maintain compatibility. TODO: Remove in some version that breaks backwards compatability