Giter Site home page Giter Site logo

ajaysinghj8 / osham Goto Github PK

View Code? Open in Web Editor NEW
55.0 7.0 6.0 820 KB

A Configurable Proxy + Cache Server.

License: MIT License

TypeScript 95.81% JavaScript 3.60% Shell 0.59%
nodejs typescript proxy proxyserver proxy-server cache cache-server cache-service redis redis-cache

osham's Introduction

ओषम् (Osham)

Total alerts Language grade: JavaScript

A Configurable Proxy Cache Server.

npx osham
 npm i -g osham
 npm i osham

What is ओषम् (Osham) ?

Osham is a cache service for APIs.

The idea behind Osham is to support higher concurrent requests with fewer resources and fast response time.

In a public facing API/frontend, most of the request remains the same and so the response is also the same. To avoid rendering the same request from the backend and to speed up the response time we should use CACHE.

The cache can solve many problems and it uses fewer backend resources to provide a good response time.

But that's not it.

In a real-world scenario, what happens when your backend is requested with hundreds of concurrent requests for the first time. In all those concurrent requests, there will be cache miss and will cause a thundering herd problem.

All of these problems and many more can be resolved by using Osham in your architecture.

Setup and Configure

  • Create a folder.
    mkdir cache
  • Move in this newly created folder
    cd cache
  • Install osham using

    npm install osham

    OR

    npm install osham -g
  • Create a .env file.

    touch .env
  • Configure and place following in the .env file.

    # Port number on the cache server will listen to incoming requests
    PORT=26192
    # Redis host name
    REDIS_HOST=localhost
    # Redis port number
    REDIS_PORT=6379
    # HTTPS Options
    SECURE=false
    SSL_KEY=
    SSL_CERT=
    # Timeout for cache service. Default is 5000 ms
    TIMEOUT=7000
    
  • Now, just need to create a cache-config.yml file. To get started copy file from here.

  • Run osham as If you have installed it using -g flag, you will be able to run it directly from cmd.

    osham

    Or

    ./node_module/.bin/osham

    Or using package.json add into scripts of package.json as "start": "osham"

    npm start
    
  • Open http://localhost:26192/api/v1/employees in the browser. Cache Server will hit the http://dummy.restapiexample.com/api/v1/employees . It will cache the result for the next 5 minutes as per over about cache configuration.

Cache Options

  • expose The proxy path which will expose from osham.

  • target The actual server HOST name (with path).

  • changeOrigin: The actual request's HOST name will be passed to backend.

  • followRedirects The HTTP/HTTPS agent will be changes to follow redirects if server has internal redirection enabled.

  • timeout Default 5000 miliseconds.

Use Cases

You are a frontend developer and you don't want to set up backend on your machine, but want a faster development experience.

To reduce TTFB on google page insights in the production environment.

To support a large number of requests with fewer resources.

Centralized many servers end-points to one.

Limitations

  1. It only supports anonymous requests.
  2. It will only cache GET requests.
  3. In Node Cluster, Requests will be pooled and served from the single response of backend per cache thread.

Architecture

Osham Archtecture

Osham Auth Arch

More Optimized Osham

Osham master slave

osham's People

Contributors

ajaysinghj8 avatar ankesh27 avatar crazyrohila avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

osham's Issues

Metrics

Is there a possibility to get metrics

  • Cache hit ratio
  • Cache miss ratio

Purge cache request

Feature request to purge cache based on

  • cache id
  • wild card cache id [APC:hotels/*]

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.