Code Monkey home page Code Monkey logo

Comments (3)

fw42 avatar fw42 commented on August 23, 2024

I'm leaning towards doing it only once and caching it and then maybe have a "expire cache" button somewhere (or cronjob) in case it needs to be refetched (people went to more competitions after registering).

from cubecomp.

timhabermaas avatar timhabermaas commented on August 23, 2024

Regarding the caching:

You can add caching directly onto Faraday and it'll work like a browser. It would be just a matter of adding expires headers to the API itself. These could be set to at least one day since the WCA export only gets updated weekly. So, performance-wise we would be covered using that solution (speaking of performance: Rust is freaking fast, it renders 35,000 competitors in 60ms (http://178.62.217.148/competitors?q=20), the single endpoint for a competitor (http://178.62.217.148/competitors/2007WEIN01) takes less than 1ms).

This wouldn't help if the API goes down for a long period of time though. The cache would be considered stale, but there would be no data to be fetched.

How would you cache the parsed responses? As attributes on the competitors table?

What I currently have in mind is a read-through cache like so:

class WCACache
  def initialize(gateway, cache)
    @gateway = gateway
    # this could be redis, a file store or MySQL.
    # It should be able to handle arbitrary data structures though. Maybe using Marshal?
    @cache = cache
  end

  def psych_sheet(puzzle_id, competitor_ids)
    result = @gateway.psych_sheet(puzzle_id, competitor_ids)
    @cache.set("psych-sheet-#{puzzle_id}-#{competitor_ids}", result)
    result
  rescue WCAGateway::ConnectionError
    @cache.get("psych-sheet-#{puzzle_id}-#{competitor_ids}") || []
  end
end

We would always fetch the most recent results unless the API is down in which case we'd return data from the cache. The cache key would need some work though. As it's currently implemented each new registration will invalidate the entire cache.

from cubecomp.

fw42 avatar fw42 commented on August 23, 2024

Rust is freaking fast

I'm not so much concerned about response time but more about network latency... unless I would host the rust thing on the same server of course.

from cubecomp.

Related Issues (20)

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.