This a Node.js and Express.js to build the API and MongoDB to store thecache data in.
- Just copy
.env.example
to.env
and fill with your einviorements:
PORT=8000
MONGO_DB_NAME=cache_db
MONGO_TEST_DB_NAME=test_db
MONGO_DB_PORT=27017
CACHE_LIMIT=10
The CACHE_LIMIT
stands for limit of existing cache on mongo.
- Install npm packages:
npm install
- To run app just call following in your command line:
npm run start:dev
- You can run project on production js too:
npm run start
You should be noticed to run tests you need mongoDb for test repository functions.
- Just copy
.env.example
to.env
and fill with your einviorements:
MONGO_TEST_DB_NAME=test_db
MONGO_DB_PORT=27017
- To run all the tests:
npm test
Base Route: https://localhost:8000
Route: /cache/keys
Method: GET
Response:
["key_1", "key_2", "key_3"]
Route: /cache/keys/DATA_KEY
Method: GET
Response:
{
"_id": "606c968569a73d64845a72bf",
"key": "key_1617729157563",
"data": { "msg": "dummy" },
"date": "2021-04-06T17:12:37.568Z",
"__v": 0,
}
Route: /cache/keys/DATA_KEY
Method: DELETE
Response:
{ "deletedCount": 1 }
Route: /cache/keys
Method: DELETE
Response:
{ "deletedCount": 10 }
Route: /cache/keys/DATA_KEY
Method: PUT
Body:
{ "msg": "dummy" } //The data that you want to be cached
Response:
{
"_id": "606c968569a73d64845a72bf",
"key": "key_1617729157563",
"data": { "msg": "dummy" },
"date": "2021-04-06T17:12:37.568Z",
"__v": 0,
}
Each object just alive for 1 minuet (60 seconds).