{"id":29791434,"url":"https://github.com/anshg1214/cacherocket","last_synced_at":"2026-04-10T00:58:29.126Z","repository":{"id":242017700,"uuid":"616449854","full_name":"anshg1214/CacheRocket","owner":"anshg1214","description":"CacheRocket is a Golang server that serves GET requests for data from two endpoints /posts/:id and /todos/:id using data fetched from Typicode.","archived":false,"fork":false,"pushed_at":"2023-03-23T10:17:04.000Z","size":117,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-05-31T06:59:09.724Z","etag":null,"topics":["docker","docker-compose","gin","go","golang","redis"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anshg1214.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-20T12:15:37.000Z","updated_at":"2024-05-31T06:59:16.586Z","dependencies_parsed_at":"2024-05-31T07:09:17.114Z","dependency_job_id":null,"html_url":"https://github.com/anshg1214/CacheRocket","commit_stats":null,"previous_names":["anshg1214/cacherocket"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/anshg1214/CacheRocket","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anshg1214%2FCacheRocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anshg1214%2FCacheRocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anshg1214%2FCacheRocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anshg1214%2FCacheRocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anshg1214","download_url":"https://codeload.github.com/anshg1214/CacheRocket/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anshg1214%2FCacheRocket/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267443338,"owners_count":24087984,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","docker-compose","gin","go","golang","redis"],"created_at":"2025-07-28T00:16:15.074Z","updated_at":"2025-12-30T21:57:34.949Z","avatar_url":"https://github.com/anshg1214.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CacheRocket: Caching API Server\n\nThis project is a simple API server built using GoLang that serves GET requests for data from two different endpoints: `/posts/:id` and `/todos/:id`. The data is fetched from https://jsonplaceholder.typicode.com and returned to the user.\n\nIn addition to serving data, the project also includes a `generic middleware` for caching API responses. This middleware caches data served over the API so that if the same API is called with the same parameters again, the response is served from the cache instead. The caching middleware is configurable, and can be enabled or disabled for a particular route.\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src='./diagram.png' height='400' alt='Diagram of the project flow'/\u003e\n\u003c/p\u003e\n\n## Table of Contents\n\n-   [CacheRocket: Caching API Server](#cacherocket-caching-api-server)\n    -   [Table of Contents](#table-of-contents)\n    -   [Technologies Used](#technologies-used)\n    -   [Installation](#installation)\n        -   [With Docker](#with-docker)\n        -   [Without Docker](#without-docker)\n        -   [ENV Variables](#env-variables)\n    -   [Code Organization](#code-organization)\n    -   [API Endpoints](#api-endpoints)\n    -   [Unit Tests](#unit-tests)\n    -   [License](#license)\n\n## Technologies Used\n\n-   [GoLang](https://golang.org/) - A programming language that makes it easy to build simple, reliable, and efficient software\n-   [Gin](https://gin-gonic.com/) - A web framework written in Go (Golang)\n-   [Redis](https://redis.io/) - An in-memory data structure store, used as a database, cache and message broker\n-   [Docker](https://www.docker.com/) - A platform for developers and sysadmins to build, run, and share applications with containers\n-   [Docker Compose](https://docs.docker.com/compose/) - A tool for defining and running multi-container Docker applications\n\n## Installation\n\nTo install the project, follow these steps:\n\n### With Docker\n\n1. Clone the project repository from GitHub using `git clone https://github.com/anshg1214/CacheRocket`\n2. Navigate to the project directory using `cd CacheRocket`\n3. Run `cp .env.example .env` to copy the example environment file to a new file named `.env`.\n4. Run `docker compose up --build` to build the Docker image and start the container.\n5. The API server will be available at http://localhost:8080.\n\n### Without Docker\n\n**Note**: You need to have Redis installed on your machine to run the project without Docker.\n\n1. Clone the project repository from GitHub using git clone\n2. Navigate to the project directory using cd your-repo-name\n3. Run `cp .env.example .env` to copy the example environment file to a new file named `.env`\n4. Run `go mod download` to install the project dependencies\n5. Run `go build` to build the project\n6. Run `./CacheRocket` to start the server\n7. The API server will be available at http://localhost:8080.\n\n### ENV Variables\n\n1. `REDIS_URL` - The URL of the Redis server. Defaults to `localhost:6379`\n2. `CACHE_POSTS` - Whether to enable caching for the `/posts/:id` route. Defaults to `true`\n3. `CACHE_TODOS` - Whether to enable caching for the `/todos/:id` route. Defaults to `true`\n\n## Code Organization\n\nThe project is organized as follows:\n\n-   `main.go` - The main entry point for the project. This file initializes the server and routes.\n-   `config` - Contains the configuration files for the project\n-   `controller` - Contains the controller functions for the routes\n-   `middleware` - Contains the cache middleware functions for the project\n-   `Dockerfile` - The Dockerfile for the project\n-   `docker-compose.yml` - The docker-compose file for the project\n\n## API Endpoints\n\nThe project exposes the following API endpoints:\n\n-   `GET /posts/:id` - Fetches a post with the given ID from `https://jsonplaceholder.typicode.com/posts/:id`\n-   `GET /todos/:id` - Fetches a todo with the given ID from `https://jsonplaceholder.typicode.com/todos/:id`\n\n## Unit Tests\n\nThe project includes unit tests for the cache middleware.\n\nTo run the tests with Docker, run `docker compose run --rm app go test`.\nTo run the tests without Docker, run `go test`.\n\n## Performance Tests\n\nThe script `scripts/testPerformance.sh` can be used to test the performance of the API server. The script makes 5000 requests to the API server and measures the time taken to serve the requests. The script also measures the time taken to serve the same requests from the cache.\n\nNote: You need to install apache benchmark (`ab`) to run the script. On Ubuntu, you can install it using\n\n```\nsudo apt install apache2-utils\n```\n\nTo run the script, run `./scripts/testPerformance.sh`.\n\nSample output:\n\n```\n$ ./scripts/testPerformance.sh\n\n\u003e This script will compare the response times of a website when using cache and when not using cache.\n\n\u003e First sending 5000 requests to the website without using cache.\n\n\u003e ......\n\n\u003e Average response time: 145.682 miliseconds\n\u003e Minimum response time: 31.761 miliseconds\n\u003e Maximum response time: 324.365 miliseconds\n\n\n\u003e Now sending 5000 requests to the website using cache.\n\n\u003e ......\n\n\u003e Average response time: 52.526 miliseconds\n\u003e Minimum response time: 11.822 miliseconds\n\u003e Maximum response time: 109.429 miliseconds\n\n```\n\nWe can see that the average response time is reduced by 65% when using cache. The minimum response time is also reduced by 60%.\n\n## License\n\nThis project is licensed under the [MIT License](https://opensource.org/licenses/MIT). See the LICENSE file for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanshg1214%2Fcacherocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanshg1214%2Fcacherocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanshg1214%2Fcacherocket/lists"}