Skip to content

Commit

Permalink
Fix bug where cache is never checked
Browse files Browse the repository at this point in the history
  • Loading branch information
victorquinn committed Oct 7, 2024
1 parent 966dcb4 commit c023587
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "weather-plus",
"version": "0.0.17",
"version": "0.0.18",
"description": "Weather Plus is a powerful wrapper around various Weather APIs that simplifies adding weather data to your application",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
Expand Down
11 changes: 8 additions & 3 deletions src/weatherService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ export class WeatherService {
log(`Getting weather for (${lat}, ${lng})`);
const geohash = getGeohash(lat, lng, 6);

const weather = await this.providers[this.provider].getWeather(lat, lng);
await this.cache.set(geohash, JSON.stringify(weather), 300); // Cache for 5 mins
return weather;
const cachedWeather = await this.cache.get(geohash);
if (cachedWeather) {
return JSON.parse(cachedWeather);
} else {
const weather = await this.providers[this.provider].getWeather(lat, lng);
await this.cache.set(geohash, JSON.stringify(weather), 300); // Cache for 5 mins
return weather;
}
}
}

0 comments on commit c023587

Please sign in to comment.