Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logan/frozen cache #3

Open
wants to merge 1 commit into
base: fast-roles-dedupe
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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