Skip to content

Commit b0ff302

Browse files
committed
Uses proper adapter to generate a cache
1 parent 141ece6 commit b0ff302

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/Config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class Config {
3636

3737
// Create a new DatabaseController per request
3838
if (cacheInfo.databaseController) {
39-
this.database = new DatabaseController(cacheInfo.databaseController.adapter, new SchemaCache(cacheInfo.schemaCacheTTL));
39+
this.database = new DatabaseController(cacheInfo.databaseController.adapter, cacheInfo.createSchemaCache());
4040
}
4141

4242
this.serverURL = cacheInfo.serverURL;

src/Controllers/SchemaCache.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import { InMemoryCacheAdapter } from '../Adapters/Cache/InMemoryCacheAdapter';
2-
31
const CACHED_KEYS = "__CACHED_KEYS";
42
const MAIN_SCHEMA = "__MAIN_SCHEMA";
53
const SCHEMA_CACHE_PREFIX = "__SCHEMA";
64
export default class SchemaCache {
75
cache: Object;
86

9-
constructor(ttl) {
7+
constructor(adapter, ttl) {
108
this.ttl = ttl;
11-
this.cache = new InMemoryCacheAdapter({ ttl });
9+
this.cache = adapter;
1210
}
1311

1412
getAllClasses() {

src/ParseServer.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ class ParseServer {
186186
const emailControllerAdapter = loadAdapter(emailAdapter);
187187
const cacheControllerAdapter = loadAdapter(cacheAdapter, InMemoryCacheAdapter, {appId: appId});
188188

189+
const createSchemaCache = function() {
190+
let adapter = loadAdapter(cacheAdapter, InMemoryCacheAdapter, {appId: appId, ttl: schemaCacheTTL});
191+
return new SchemaCache(adapter, schemaCacheTTL);
192+
}
189193
// We pass the options and the base class for the adatper,
190194
// Note that passing an instance would work too
191195
const filesController = new FilesController(filesControllerAdapter, appId);
@@ -194,7 +198,7 @@ class ParseServer {
194198
const userController = new UserController(emailControllerAdapter, appId, { verifyUserEmails });
195199
const liveQueryController = new LiveQueryController(liveQuery);
196200
const cacheController = new CacheController(cacheControllerAdapter, appId);
197-
const databaseController = new DatabaseController(databaseAdapter, new SchemaCache(schemaCacheTTL));
201+
const databaseController = new DatabaseController(databaseAdapter, createSchemaCache());
198202
const hooksController = new HooksController(appId, databaseController, webhookKey);
199203

200204
// TODO: create indexes on first creation of a _User object. Otherwise it's impossible to
@@ -246,7 +250,8 @@ class ParseServer {
246250
expireInactiveSessions: expireInactiveSessions,
247251
revokeSessionOnPasswordReset,
248252
databaseController,
249-
schemaCacheTTL
253+
schemaCacheTTL,
254+
createSchemaCache
250255
});
251256

252257
// To maintain compatibility. TODO: Remove in some version that breaks backwards compatability

0 commit comments

Comments
 (0)