Coder Social home page Coder Social logo

cache-rules-everything-around-me's Introduction

DRAFT

Cache Rules Everything Around Me

Dollar, dollar, bills y'all.

Route: /slow is very slow (takes 5 seconds to respond)

Solution: implement caching using Redis!

Cache Miss flow

Implement a caching approach so that when the initial GET request to /api, it takes 5 seconds as usual with the exception that the response value will be saved to the cache.

Cache Hit flow

But all subsequent GET requests to /api should be served from the cache. This request should be instant, e.g. not take 5 seconds to respond. The cache should expire after 1 minute. After that the first GET request to /api will take 5 seconds to respond and the cache miss flow will occur

Implementation

A Express middleware module that can be imported onto any route on our server. The middleware function will check the cache store for the cached data for a route and serves the data in the cache back (cache hit) to the client. Otherwise, if the data has not been cached, the middleware lets the request fall-through and hit the route.

Module should have:

  • a method which returns a function that can be mounted as middleware
  • a method to save a key-value pair to the cache
  • a method to retrieve a value from the cache

Testing

How does a non-cached request differ from a request served from cache? This is your baseline for your test specifications.

Final Boss

Is there a way to achieve the goal without the getter and setter methods? Yes, but it might require some spoon-bending. After this step you will have built a caching middlware with base similarity to other popular express middlware modules. \o/ :sparkles:

Hint: "fall-through middlware"

Do not try and bend the spoon. That's impossible.

cache-rules-everything-around-me's People

Contributors

sgnl avatar vallejoj avatar joekarlsson avatar

Watchers

James Cloos avatar  avatar

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.