{"id":21672487,"url":"https://github.com/redis-developer/redis-caching-api-responses","last_synced_at":"2025-07-18T20:36:58.222Z","repository":{"id":104843748,"uuid":"341334748","full_name":"redis-developer/redis-caching-api-responses","owner":"redis-developer","description":null,"archived":false,"fork":false,"pushed_at":"2021-02-23T17:18:58.000Z","size":9,"stargazers_count":12,"open_issues_count":0,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-12T03:52:36.242Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/redis-developer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2021-02-22T20:55:26.000Z","updated_at":"2024-01-02T02:44:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"5af15f29-59e8-47c0-b0b0-d3a7a35ac5e7","html_url":"https://github.com/redis-developer/redis-caching-api-responses","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/redis-developer/redis-caching-api-responses","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fredis-caching-api-responses","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fredis-caching-api-responses/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fredis-caching-api-responses/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fredis-caching-api-responses/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redis-developer","download_url":"https://codeload.github.com/redis-developer/redis-caching-api-responses/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fredis-caching-api-responses/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265829207,"owners_count":23835090,"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","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":[],"created_at":"2024-11-25T13:29:32.974Z","updated_at":"2025-07-18T20:36:58.210Z","avatar_url":"https://github.com/redis-developer.png","language":"JavaScript","readme":"# Caching\nSimple API caching example with Redis!  This repository is based on the video [Caching API Responses with Redis](https://youtu.be/hRecenOBYlE). For further information on caching, check out these videos as well:\n\n- [What is Caching?](https://youtu.be/NCnVw7ew9do)\n- [Caching Slow Database Queries](https://youtu.be/Ph4W3pWA3eY)\n\n## Prerequisites\n- Node.js\n- Redis\n- axios\n- ioredis\n- [Open Weather Map API Key ](https://openweathermap.org/api)\n\n## Installing this application\n\nClone the repository to your computer:\n\n```bash\ngit clone https://github.com/redis-developer/redis-caching-api-responses\n```\n\nInstall dependencies:\n```bash\nnpm install \n```\n\nAdd the Open Weather Map API Key to your Environment Variables:\n```bash\nexport WEATHER_API_KEY=\u003cyour api key\u003e\n```\n\n## Database Preparation\n\nEnsure you have Redis installed and running.\n\nFor Docker:\n```bash\n$ docker run -p 6379:6379 --name redis6 -d redis:6 \n```\n\n### `api.js`\n\nThis file contains logic to demonstrate caching entries from a weather service API.  You will need a free API key of your own to run this demonstration. You can get your own API key by following the [instructions at the Open WeatherMap API](https://openweathermap.org/api) site.  The `getWeather()` function retrieves a JSON object containing real-time meteorological information on a given city. This example uses Oakland, but you can use whichever city you like.\n\nEnsure Redis is running, then run the `api.js` file once.  Since there is no cache entry, the code will retrieve the data from the Open Weather Map API.\n\n```bash\n$ node api.js\n{\n  coord: { lon: -83.4, lat: 42.67 },\n  weather: [\n    {\n      id: 803,\n      main: 'Clouds',\n      description: 'broken clouds',\n      icon: '04d'\n    }\n  ],\n  ...\n  source: 'API',\n  responseTime: '180ms'\n}\n```\n\nThe code will have placed a copy of the entry in the Redis cache, so the next function call will return data from the cache. Note that the cached entry has a `TTL` (Time To Live) of one hour. Weather can change frequently, so an hour should provide a reasonable approximation of the current conditions. After an hour, the cache entry will be removed automatically, and a new cache entry will need to be stored. This ensures fresh, relevant data.\n\n```bash\n$ node api.js\n{\n  coord: { lon: -83.4, lat: 42.67 },\n  weather: [\n    {\n      id: 803,\n      main: 'Clouds',\n      description: 'broken clouds',\n      icon: '04d'\n    }\n  ],\n  ...\n  source: 'cache',\n  responseTime: '9ms'\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis-developer%2Fredis-caching-api-responses","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredis-developer%2Fredis-caching-api-responses","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis-developer%2Fredis-caching-api-responses/lists"}