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

feat: SJIP-973 add cache for diffGeneExp #212

Merged
merged 1 commit into from
Oct 28, 2024
Merged
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
20 changes: 15 additions & 5 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ import { getStatistics, getStudiesStatistics } from './endpoints/statistics';
import { checkSampleIdsAndGene, fetchDiffGeneExp, fetchFacets, fetchSampleGeneExp } from './endpoints/transcriptomics';
import { cacheTTL, esHost, keycloakURL, userApiURL } from './env';
import { globalErrorHandler, globalErrorLogger } from './errors';
import { STATISTICS_CACHE_ID, STATISTICS_PUBLIC_CACHE_ID, verifyCache } from './middleware/cache';
import {
STATISTICS_CACHE_ID,
STATISTICS_PUBLIC_CACHE_ID,
TRANSCRIPTOMICS_DIFF_GENE_EXP_CACHE_ID,
verifyCache,
} from './middleware/cache';
import { injectBodyHttpHeaders } from './middleware/injectBodyHttpHeaders';
import { resolveSetIdMiddleware } from './middleware/resolveSetIdInSqon';

Expand Down Expand Up @@ -149,11 +154,16 @@ export default (keycloak: Keycloak, getProject: (projectId: string) => ArrangerP
res.send({ data });
});

app.postAsync('/transcriptomics/diffGeneExp', keycloak.protect(), async (req, res) => {
const data = await fetchDiffGeneExp();
app.postAsync(
'/transcriptomics/diffGeneExp',
[keycloak.protect(), verifyCache(TRANSCRIPTOMICS_DIFF_GENE_EXP_CACHE_ID, cache)],
async (req, res) => {
const data = await fetchDiffGeneExp();
cache.set(TRANSCRIPTOMICS_DIFF_GENE_EXP_CACHE_ID, data);

res.json(data);
});
res.json(data);
},
);

app.postAsync('/transcriptomics/sampleGeneExp', keycloak.protect(), async (req, res) => {
const ensembl_gene_id: string = req.body.ensembl_gene_id;
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { NextFunction, Request, Response } from 'express';
import NodeCache from 'node-cache';

export const STATISTICS_CACHE_ID = 'statistics';

export const STATISTICS_PUBLIC_CACHE_ID = 'statistics_studies';
export const TRANSCRIPTOMICS_DIFF_GENE_EXP_CACHE_ID = 'transcriptomics_diff_gene_exp';

export const verifyCache = (cacheId: string, cache: NodeCache) => (
_req: Request,
Expand Down
Loading