Skip to content

Commit

Permalink
Use new FrozenCacheAdapter for schema cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Logan Buckley committed Sep 21, 2020
1 parent 56fb66d commit c02ee69
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hustle/parse-server",
"version": "4.3.0-fast-roles-dedupe",
"version": "4.3.0-hustle4",
"description": "An express module providing a Parse-compatible API server",
"main": "lib/index.js",
"repository": {
Expand Down
30 changes: 30 additions & 0 deletions src/Adapters/Cache/FrozenCacheAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export class FrozenCacheAdapter {
constructor() {
this.cache = {};
}

get(key) {
const record = this.cache[key];
if (!record) {
return Promise.resolve(null);
}
return Promise.resolve(record);
}

// eslint-disable-next-line no-unused-vars
put(key, value, ttl) {
this.cache[key] = value;
return Promise.resolve();
}

del(key) {
delete this.cache[key];
return Promise.resolve();
}

clear() {
return Promise.resolve();
}
}

export default FrozenCacheAdapter;
6 changes: 4 additions & 2 deletions src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class Config {
Object.keys(cacheInfo).forEach(key => {
if (key == 'databaseController') {
const schemaCache = new SchemaCache(
cacheInfo.cacheController,
cacheInfo.schemaCacheController,
cacheInfo.schemaCacheTTL,
cacheInfo.enableSingleSchemaCache
);
Expand Down Expand Up @@ -114,7 +114,9 @@ export class Config {
}

static validateIdempotencyOptions(idempotencyOptions) {
if (!idempotencyOptions) { return; }
if (!idempotencyOptions) {
return;
}
if (idempotencyOptions.ttl === undefined) {
idempotencyOptions.ttl = IdempotencyOptions.ttl.default;
} else if (!isNaN(idempotencyOptions.ttl) && idempotencyOptions.ttl <= 0) {
Expand Down
9 changes: 9 additions & 0 deletions src/Controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import SchemaCache from './SchemaCache';
import { GridFSBucketAdapter } from '../Adapters/Files/GridFSBucketAdapter';
import { WinstonLoggerAdapter } from '../Adapters/Logger/WinstonLoggerAdapter';
import { InMemoryCacheAdapter } from '../Adapters/Cache/InMemoryCacheAdapter';
import { FrozenCacheAdapter } from '../Adapters/Cache/FrozenCacheAdapter';
import { AnalyticsAdapter } from '../Adapters/Analytics/AnalyticsAdapter';
import MongoStorageAdapter from '../Adapters/Storage/Mongo/MongoStorageAdapter';
import PostgresStorageAdapter from '../Adapters/Storage/Postgres/PostgresStorageAdapter';
Expand All @@ -39,6 +40,7 @@ export function getControllers(options: ParseServerOptions) {
pushWorker,
} = getPushController(options);
const cacheController = getCacheController(options);
const schemaCacheController = getSchemaCacheController(options);
const analyticsController = getAnalyticsController(options);
const liveQueryController = getLiveQueryController(options);
const databaseController = getDatabaseController(options, cacheController);
Expand All @@ -59,6 +61,7 @@ export function getControllers(options: ParseServerOptions) {
pushControllerQueue,
analyticsController,
cacheController,
schemaCacheController,
parseGraphQLController,
liveQueryController,
databaseController,
Expand Down Expand Up @@ -126,6 +129,12 @@ export function getUserController(options: ParseServerOptions): UserController {
});
}

export function getSchemaCacheController(options: ParseServerOptions) {
const { appId } = options;
const cacheAdapter = new FrozenCacheAdapter();
return new CacheController(cacheAdapter, appId);
}

export function getCacheController(
options: ParseServerOptions
): CacheController {
Expand Down

0 comments on commit c02ee69

Please sign in to comment.