Embedded distributed caching within multiple servers using the groupcache library.
To set up the development environment, ensure that you have Go installed. You can download and install Go from the official Go website.
To start the application, use the following command:
make start
To stop the application and free up the used ports, use the following command:
make stop
To clear all build files, use the following command:
make clean
You can test the caching mechanism using curl commands.
First Request (Fetch from DB and Cache)
curl --location 'http://localhost:8081?key=apple'
This is the first request, so the data will be fetched from the database, store it in the cache, and then returned in the response.
Subsequent Requests (Fetch from Cache)
curl --location 'http://localhost:8082?key=apple'
curl --location 'http://localhost:8083?key=apple'
curl --location 'http://localhost:8084?key=apple'
These requests will return the response from the cache, provided the cache has not expired.