This project is a simple demonstration of how to cache API responses using Redis in a Node.js (Express) server. It uses the JSONPlaceholder API to fetch photo data and caches it for faster repeat access.
- Fetch and cache list of photos (
/photos?albumId=1) - Fetch and cache individual photo by ID (
/photos/:id) - Caching powered by Redis with expiration time
- Simple and clean middleware logic
- Uses Axios for HTTP requests
https://github.com/your-username/basic-redis-caching.git
cd basic-redis-cachingnpm installYou can install Redis quickly depending on your OS:
- Windows: Use this guide
- macOS (Homebrew):
brew install redis
brew services start redis- Ubuntu/Linux:
sudo apt update
sudo apt install redis-server
sudo systemctl enable redis-server.service- Verify Redis:
redis-cli ping # Output should be: PONGDetailed Redis installation guide: https://redis.io/docs/getting-started/installation/
nodemon server.jsServer runs on
http://localhost:3000
- Fetches all photos from album 1
- Response is cached for 1 hour (3600s)
- Fetches a single photo by ID
- Response is cached individually
Pull requests welcome! For major changes, open an issue first to discuss what you want to change.
Built by Dhaval Bhimani with ☕ and a lot of curiosity.
- Redis Docs: https://redis.io/docs
- JSONPlaceholder API: https://jsonplaceholder.typicode.com
- Axios: https://axios-http.com
- Express: https://expressjs.com/