Skip to content

Commit

Permalink
feat: cache only GET all resources
Browse files Browse the repository at this point in the history
Use apicache on GET all workouts, records and members.
  • Loading branch information
JSamuelAP committed Oct 20, 2023
1 parent 2bf96e7 commit cbc1b25
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crossfit-wod-api",
"version": "1.9.2",
"version": "1.9.3",
"description": "Crossfit Work Of Day REST API from freeCodeCamp",
"main": "index.js",
"type": "module",
Expand Down
9 changes: 8 additions & 1 deletion src/v1/routes/memberRoutes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Router } from "express";
import { body } from "express-validator";
import apicache from "apicache";
const cache = apicache.middleware;

import {
getAllMembers,
Expand All @@ -18,7 +20,12 @@ import { validateFields } from "../../middlewares/validateFields.js";

const router = Router();

router.get("/", [lengthIsInt(), pageisInt(), validateFields], getAllMembers);
router.get(
"/",
cache("2 minutes"),
[lengthIsInt(), pageisInt(), validateFields],
getAllMembers
);

router.get(
"/:memberId",
Expand Down
9 changes: 8 additions & 1 deletion src/v1/routes/recordRoutes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Router } from "express";
import { body } from "express-validator";
import apicache from "apicache";
const cache = apicache.middleware;

import {
getAllRecords,
Expand All @@ -17,7 +19,12 @@ import { validateFields } from "../../middlewares/validateFields.js";

const router = Router();

router.get("/", [lengthIsInt(), pageisInt(), validateFields], getAllRecords);
router.get(
"/",
cache("2 minutes"),
[lengthIsInt(), pageisInt(), validateFields],
getAllRecords
);

router.get(
"/:recordId",
Expand Down
9 changes: 8 additions & 1 deletion src/v1/routes/workoutRoutes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Router } from "express";
import { body } from "express-validator";
import apicache from "apicache";
const cache = apicache.middleware;

import {
getAllWorkouts,
Expand All @@ -19,7 +21,12 @@ import {

const router = Router();

router.get("/", [lengthIsInt(), pageisInt(), validateFields], getAllWorkouts);
router.get(
"/",
cache("2 minutes"),
[lengthIsInt(), pageisInt(), validateFields],
getAllWorkouts
);

router.get(
"/:workoutId",
Expand Down

0 comments on commit cbc1b25

Please sign in to comment.