Skip to content

Instantly share code, notes, and snippets.

@d11wtq
Created August 14, 2012 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d11wtq/3347995 to your computer and use it in GitHub Desktop.
Save d11wtq/3347995 to your computer and use it in GitHub Desktop.
An awesome caching proxy should...
Imagine something like:
var http = require('http')
, cache = require('cache')
;
var options = {
ignoreCookies: true,
cacheStatics: 300 // 5 minutes, unless an explicit cache-control header is given
};
http.createServer( // bog standard node
new cache.WriteThroughCache(function(req, res) { // wrap the usual handler in a write-through cache
// all of the usual node things
}, options)
).listen(80);
Where in reality the server function would be the http-proxy one, which we use for routing to our PHP/Rails/nginx servers. Though it could be anything that writes HTTP responses. This is complete pseudo-code. I have no idea what shape this will take when I actually write it.
What would make it more awesome than Varnish and Squid?
* Routing and caching contained to a single process = less HTTP hops
* Being written in node.js = insane concurrency support
* Being written in node.js = flexibility
* Being written in node.js = potential to *eventually* do SSL unwrapping and load balancing all in one process
* Being written in node.js = support for websockets
Assuming that by default the cache is RFC2616 compliant, what options should it support to make it useful as a really agressive cache?
* Ability to force a resource to be cached, even if some factors would otherwise prevent it
- is this just cookies in practice, or are there other things?
- perhaps list headers to ignore if Cache-Control says to cache?
- allow a callback function to be supplied to do this work?
* Is caching on disk slow?
- use memory if possible? multiple "storage" implementations with a defined interface?
- use a mix of memory/disk?
* what stays in memory for longer? recently accessed? most frequently accessed? smallest file sizes?
* Should responses for static file types that don't provide a Cache-Control header be cached for some period of time anyway?
What types of things do we fine tune in Squid/Varnish that one might overlook, if they were just following RFC2616 to the letter?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment