Have you ever wanted to convert your very slow and resistant to change website/blog with tons of content to something really cool using modern technos (like mobile app or API centric web app)? We'll try to do that.
Let's build a cache server using NodeJS. The main idea is: when a request arrives, check if it is already cached, if yes, render it immediately, if not, proxify the request and store (cache) the content in your cache server, and then, render the result. Simple, isn't it? Check this article for more info about the idea.
The steps:
You can use this simple API if you don't know which one to use:
http://cultiz.com/api/get_posts/
: list of articles (oyu can use ?count=
to limit the number of items)http://cultiz.com/api/get_post/?post_id=23668
: get 1 article (by ID or by slug: ?post_slug=
)When I go to http://localhost:1234/get_posts
I should get the JSON result I asked for, not cached the first (~4 s response time), cached then (~40 ms response time).
February 26 2015
Around 2 hours
Less than 200
GET and DELETE routes should be enough for this puzzle
Redis need to be installed and the server should run ;) > redis-server
.
You can also test what has been stored using the Redis client: > redis-cli
& > KEYS *
.
In Redis, you can just use GET, SET, EXISTS and DEL commands like this redisClient.set(key, value, function(error){ })
.
If you have trouble setting a new key in Redis, you can use "crypto" to encode the requested URL into a unique string.