https://github.com/max9159/keyvaluestore
The KeyValueStore is a key-value in-memory store service with cache mechanism written in NodeJS programming language.
https://github.com/max9159/keyvaluestore
cache cache-service fifo lock nodejs
Last synced: 3 months ago
JSON representation
The KeyValueStore is a key-value in-memory store service with cache mechanism written in NodeJS programming language.
- Host: GitHub
- URL: https://github.com/max9159/keyvaluestore
- Owner: max9159
- Created: 2022-07-28T16:17:03.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-07-28T16:31:09.000Z (almost 3 years ago)
- Last Synced: 2025-01-26T17:22:39.606Z (5 months ago)
- Topics: cache, cache-service, fifo, lock, nodejs
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# KeyValueStore
> The **KeyValueStore** is a key-value in-memory store service with cache mechanism written in NodeJS programming language.> It including a fake store service getting data from DataBase (Mock data would be generated in-memory) and cache mechanism to practice any design-patten.
> Currently, it supports the thread-safe with Locks and cache replacement policy FIFO (Also flexible to change policy by injection).
## Installation
- Ensure you have install NodeJS.
- https://nodejs.org/en/download/
```bash
npm install
```## Getting Started
- To start **KeyValueStore** API service.
```bash
npm start
```## API Request Example
```console
## GET
curl --location --request GET "http://localhost:3000/api/store?key=3"## POST
curl --location --request POST "http://localhost:3000/api/store" --header "Content-Type: application/json" --data-raw "{ \"key\": \"3\", \"value\": \"value3\"}"```
## Unit-Tests
- Run testing command.
```bash
npm run test
```
- All of test cases in [keyValueStore.test](./test/keyValueStore.test.js)## API-Tests
- [integrationTests.http](./test/integrationTests.http)
- Use above http file via plugin can send HTTP request such as [HTTP Client of IntelliJ](https://www.jetbrains.com/help/idea/http-client-in-product-code-editor.html) or [REST Client of VSCode Extension](https://marketplace.visualstudio.com/items?itemName=humao.rest-client)## Configuration
- [cacheConfigs](./config/cacheConfigs.js)
- Can setup cache service's **MAXIMUM_BYTES_SIZE** and **REPLACEMENT_POLICY**
- Currently supports **FIFO**, can add new strategy and implement the same as interface of [fifoStrategy.js](./service/fifoStrategy.js)## Lock in NodeJS
- To prevent race condition the **KeyValueStore** implement lock mechanism in [Locker](./util/locker.js)## Mock Data
- Mock data has been generated in the constructor of the [storeService](./service/storeService.js).
- The [storeService](./service/storeService.js) to pretend to be a DataBase store service.