Giter VIP home page Giter VIP logo

simple-cache's Introduction

Simple Cache in Python

Cache server

This is a simple cache server in python. I wrote about it here.

Fetching item from cache server, who fetches from main server

Here are the steps for the first time an item is requested:

  1. Client requests item
  2. Cache server checks if it's stored in the cache
  3. The item is not found
  4. The cache server requests the item from the main server
  5. The main server sends the item back
  6. The cache server saves a copy of the item
  7. The cache server sends the client the item

We could definitely swap 6 and 7, especially if we're trying to send the item back to the client quickly.

Here's a diagram of a subsequent request for the same item:.

Fetching item from cache server, who has it locally

Here are the steps for the future request:

  1. Client requests item
  2. Cache server checks if it's stored in the cache
  3. The item is found
  4. The cache server sends the client the item

Although it looks like the main server is lonely to the right, it didn't have to worry about the client's request at all. Lucky main server!

Here's another way of looking at the problem. Here, the vertical axis is time increasing as you go down, and the horizontal arrows are the requests back and forth. The same actions are taken in the same exact order, but the actions are separated vertically by when they happen:

Fetching item from cache server, timeline

Usage

First, start the simple http server from the main_server directory: python httpserver.py 8000

Then, start the cache proxy server in a separate terminal instance from the cache_server directory: python cacheproxy.py 8001

Then, navigate or curl to localhost:8001.

Result: Caching server in action

References

Thanks to joaoventura for the simple http server code!

simple-cache's People

Contributors

alexanderellis avatar

Watchers

James Cloos 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.