Comments (1)
Excellent idea!
Here are a few design suggestions that could achieve this in a very simple manner:
- The cache can be a
map
attached to theserver
, or some other struct.
a.lat,lng
is the key.
b. note that maps are not thread safe, so we need to ensure we add proper mutex mechanics. - The forecast fetcher starts with the server, in a separate go routine.
a. It continues running until the server receives a shutdown signal. - When a request comes in, we check the cache for a key.
- if it doesn't exist, call the noaa API
- if it does, ensure the timestamp on the caches value is new enough (eg 1000 seconds)
- if new enough, return cached value
- if too old, call noaa API
- All noaa requests made (due to cache miss or otherwise) always refresh the cache for the
lat,lng
(key).
Along with simplicity, a primary benefit is our API remains as is since the complexity around cache logic is buried into the implementation details retrieval. This is great for clients that don't need to understand where the data is coming from. We also no longer need to set TTLs with our http calls.
Here's a quick visual to make this idea a bit concrete (missing some nuance in the bullets above):
Let me know your thoughts!
from cragcast.
Related Issues (7)
- Support per-crag weather profiles with sun/shade and conditions properties
- Investigate noaa-client model/sdk generation based on OpenAPI spec
- Support weather radars attached to climbing areas
- NWS api is missing data(precip amount and sky cover) HOT 1
- Transfer repository to cragcast organization
- Add golangci-lint to `make` and GH actions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cragcast.