Skip to content

Commit

Permalink
Uses proper adapter to generate a cache
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart committed Jul 15, 2016
1 parent 5383d0d commit 0514769
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/Controllers/SchemaCache.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
9 changes: 7 additions & 2 deletions src/ParseServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0514769

Please sign in to comment.