Coder Social home page Coder Social logo

nodish's Introduction

Nodish - An alternative of Varnish Cache in node.js

We use Varnish between the client and our backend server. It helps to support more concurrent accesses to our website. However, you need to use the domain specific language "VCL" to define the cache policy. I don't like it much. I prefer writing Javascript. Nodish is a pure Javascript (node.js) solution to replace Varnish in your server.

The philosophy

There is only one single file in this project, server.js. The main proxy server logic is included in this file. There are also few pre-defined functions that help you build your own cache strategy. You may want to study each function to get to know what they are doing.

How to use

Define your own cache strategy

For a simple use case, you may just need to write your own cache logic in the function recv(). Yes. The naming strategy is a bit similar to Varnish such that you could be more familiar with the environment.

The cache logic that I am using in a production server is included for your reference. The arguments req and res are the request and response object provided by node.js. That means you can read/write any properties from/to them as you would do to other node.js application. (This is also why I prefer doing it in node.js instead of VCL)

Point to the backend server

There is a function called forwardRequest(). As the name suggested, it forwards the request to the backend server. At this moment, the request info is coded inside this function. You may need to change the host name and the port to fit your use case.

Run the server

In my environment, I can start the server by this command.

sudo node server.js

That simple. This starts a proxy server listening to port 80.

License

WTFPL is used. Do What The Fuck You Want To Public License

In short, you just DO WHAT THE FUCK YOU WANT TO.

nodish's People

Contributors

alex621 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.