Adding Caching Adapter, allows caching of _Role and _User queries (fixes #168) (#1664)

* Adding Caching Adapter, allows caching of _Role and _User queries.
This commit is contained in:
Blayne Chard
2016-05-18 12:12:30 +12:00
parent 5d887e18f0
commit 8c09c3dae1
18 changed files with 526 additions and 134 deletions

View File

@@ -15,8 +15,8 @@ if (!global._babelPolyfill) {
}
import { logger,
configureLogger } from './logger';
import cache from './cache';
configureLogger } from './logger';
import AppCache from './cache';
import Config from './Config';
import parseServerPackage from '../package.json';
import PromiseRouter from './PromiseRouter';
@@ -24,6 +24,8 @@ import requiredParameter from './requiredParameter';
import { AnalyticsRouter } from './Routers/AnalyticsRouter';
import { ClassesRouter } from './Routers/ClassesRouter';
import { FeaturesRouter } from './Routers/FeaturesRouter';
import { InMemoryCacheAdapter } from './Adapters/Cache/InMemoryCacheAdapter';
import { CacheController } from './Controllers/CacheController';
import { FileLoggerAdapter } from './Adapters/Logger/FileLoggerAdapter';
import { FilesController } from './Controllers/FilesController';
import { FilesRouter } from './Routers/FilesRouter';
@@ -104,6 +106,7 @@ class ParseServer {
serverURL = requiredParameter('You must provide a serverURL!'),
maxUploadSize = '20mb',
verifyUserEmails = false,
cacheAdapter,
emailAdapter,
publicServerURL,
customPages = {
@@ -156,6 +159,8 @@ class ParseServer {
const pushControllerAdapter = loadAdapter(push && push.adapter, ParsePushAdapter, push);
const loggerControllerAdapter = loadAdapter(loggerAdapter, FileLoggerAdapter);
const emailControllerAdapter = loadAdapter(emailAdapter);
const cacheControllerAdapter = loadAdapter(cacheAdapter, InMemoryCacheAdapter, {appId: appId});
// 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);
@@ -164,8 +169,9 @@ class ParseServer {
const hooksController = new HooksController(appId, collectionPrefix);
const userController = new UserController(emailControllerAdapter, appId, { verifyUserEmails });
const liveQueryController = new LiveQueryController(liveQuery);
const cacheController = new CacheController(cacheControllerAdapter, appId);
cache.apps.set(appId, {
AppCache.put(appId, {
masterKey: masterKey,
serverURL: serverURL,
collectionPrefix: collectionPrefix,
@@ -175,6 +181,7 @@ class ParseServer {
restAPIKey: restAPIKey,
fileKey: fileKey,
facebookAppIds: facebookAppIds,
cacheController: cacheController,
filesController: filesController,
pushController: pushController,
loggerController: loggerController,
@@ -195,11 +202,11 @@ class ParseServer {
// To maintain compatibility. TODO: Remove in some version that breaks backwards compatability
if (process.env.FACEBOOK_APP_ID) {
cache.apps.get(appId)['facebookAppIds'].push(process.env.FACEBOOK_APP_ID);
AppCache.get(appId)['facebookAppIds'].push(process.env.FACEBOOK_APP_ID);
}
Config.validate(cache.apps.get(appId));
this.config = cache.apps.get(appId);
Config.validate(AppCache.get(appId));
this.config = AppCache.get(appId);
hooksController.load();
}