Skip to content

Commit 76cada2

Browse files
Logan BuckleyTylerBrock
Logan Buckley
authored andcommitted
Use new FrozenCacheAdapter for schema cache
1 parent 2f69ea5 commit 76cada2

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hustle/parse-server",
3-
"version": "4.3.0-fast-roles-dedupe",
3+
"version": "4.3.0-hustle4",
44
"description": "An express module providing a Parse-compatible API server",
55
"main": "lib/index.js",
66
"repository": {
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export class FrozenCacheAdapter {
2+
constructor() {
3+
this.cache = {};
4+
}
5+
6+
get(key) {
7+
const record = this.cache[key];
8+
if (!record) {
9+
return Promise.resolve(null);
10+
}
11+
return Promise.resolve(record);
12+
}
13+
14+
// eslint-disable-next-line no-unused-vars
15+
put(key, value, ttl) {
16+
this.cache[key] = value;
17+
return Promise.resolve();
18+
}
19+
20+
del(key) {
21+
delete this.cache[key];
22+
return Promise.resolve();
23+
}
24+
25+
clear() {
26+
return Promise.resolve();
27+
}
28+
}
29+
30+
export default FrozenCacheAdapter;

src/Config.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class Config {
2929
Object.keys(cacheInfo).forEach(key => {
3030
if (key == 'databaseController') {
3131
const schemaCache = new SchemaCache(
32-
cacheInfo.cacheController,
32+
cacheInfo.schemaCacheController,
3333
cacheInfo.schemaCacheTTL,
3434
cacheInfo.enableSingleSchemaCache
3535
);
@@ -114,7 +114,9 @@ export class Config {
114114
}
115115

116116
static validateIdempotencyOptions(idempotencyOptions) {
117-
if (!idempotencyOptions) { return; }
117+
if (!idempotencyOptions) {
118+
return;
119+
}
118120
if (idempotencyOptions.ttl === undefined) {
119121
idempotencyOptions.ttl = IdempotencyOptions.ttl.default;
120122
} else if (!isNaN(idempotencyOptions.ttl) && idempotencyOptions.ttl <= 0) {

src/Controllers/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import SchemaCache from './SchemaCache';
2121
import { GridFSBucketAdapter } from '../Adapters/Files/GridFSBucketAdapter';
2222
import { WinstonLoggerAdapter } from '../Adapters/Logger/WinstonLoggerAdapter';
2323
import { InMemoryCacheAdapter } from '../Adapters/Cache/InMemoryCacheAdapter';
24+
import { FrozenCacheAdapter } from '../Adapters/Cache/FrozenCacheAdapter';
2425
import { AnalyticsAdapter } from '../Adapters/Analytics/AnalyticsAdapter';
2526
import MongoStorageAdapter from '../Adapters/Storage/Mongo/MongoStorageAdapter';
2627
import PostgresStorageAdapter from '../Adapters/Storage/Postgres/PostgresStorageAdapter';
@@ -39,6 +40,7 @@ export function getControllers(options: ParseServerOptions) {
3940
pushWorker,
4041
} = getPushController(options);
4142
const cacheController = getCacheController(options);
43+
const schemaCacheController = getSchemaCacheController(options);
4244
const analyticsController = getAnalyticsController(options);
4345
const liveQueryController = getLiveQueryController(options);
4446
const databaseController = getDatabaseController(options, cacheController);
@@ -59,6 +61,7 @@ export function getControllers(options: ParseServerOptions) {
5961
pushControllerQueue,
6062
analyticsController,
6163
cacheController,
64+
schemaCacheController,
6265
parseGraphQLController,
6366
liveQueryController,
6467
databaseController,
@@ -126,6 +129,12 @@ export function getUserController(options: ParseServerOptions): UserController {
126129
});
127130
}
128131

132+
export function getSchemaCacheController(options: ParseServerOptions) {
133+
const { appId } = options;
134+
const cacheAdapter = new FrozenCacheAdapter();
135+
return new CacheController(cacheAdapter, appId);
136+
}
137+
129138
export function getCacheController(
130139
options: ParseServerOptions
131140
): CacheController {

0 commit comments

Comments
 (0)