Code Monkey home page Code Monkey logo

Comments (1)

joshrosso avatar joshrosso commented on July 23, 2024

Excellent idea!

Here are a few design suggestions that could achieve this in a very simple manner:

  1. The cache can be a map attached to the server, 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.
  2. The forecast fetcher starts with the server, in a separate go routine.
    a. It continues running until the server receives a shutdown signal.
  3. 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
  4. 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):

image

Let me know your thoughts!

from cragcast.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.