{"action":"created","issue":{"url":"https://api.github.com/repos/mholt/caddy/issues/10","repository_url":"https://api.github.com/repos/mholt/caddy","labels_url":"https://api.github.com/repos/mholt/caddy/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/mholt/caddy/issues/10/comments","events_url":"https://api.github.com/repos/mholt/caddy/issues/10/events","html_url":"https://github.com/mholt/caddy/issues/10","id":71639756,"number":10,"title":"Cache middleware","user":{"login":"mholt","id":1128849,"avatar_url":"https://avatars.githubusercontent.com/u/1128849?v=3","gravatar_id":"","url":"https://api.github.com/users/mholt","html_url":"https://github.com/mholt","followers_url":"https://api.github.com/users/mholt/followers","following_url":"https://api.github.com/users/mholt/following{/other_user}","gists_url":"https://api.github.com/users/mholt/gists{/gist_id}","starred_url":"https://api.github.com/users/mholt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mholt/subscriptions","organizations_url":"https://api.github.com/users/mholt/orgs","repos_url":"https://api.github.com/users/mholt/repos","events_url":"https://api.github.com/users/mholt/events{/privacy}","received_events_url":"https://api.github.com/users/mholt/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/mholt/caddy/labels/help%20wanted","name":"help wanted","color":"159818"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":23,"created_at":"2015-04-28T16:36:03Z","updated_at":"2016-04-12T17:16:58Z","closed_at":null,"body":"Caddy needs a cache middleware.\r\n\r\nI'll be working on something basic this week. Probably just a basic LRU replacement algorithm and a configurable expiration time. In fact, if the gain is significant in nearly all cases, maybe it should be enabled by default... (a rare exception to the rule that all middleware need to be enabled explicitly using the Caddyfile)."},"comment":{"url":"https://api.github.com/repos/mholt/caddy/issues/comments/209013278","html_url":"https://github.com/mholt/caddy/issues/10#issuecomment-209013278","issue_url":"https://api.github.com/repos/mholt/caddy/issues/10","id":209013278,"user":{"login":"joushou","id":176245,"avatar_url":"https://avatars.githubusercontent.com/u/176245?v=3","gravatar_id":"","url":"https://api.github.com/users/joushou","html_url":"https://github.com/joushou","followers_url":"https://api.github.com/users/joushou/followers","following_url":"https://api.github.com/users/joushou/following{/other_user}","gists_url":"https://api.github.com/users/joushou/gists{/gist_id}","starred_url":"https://api.github.com/users/joushou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joushou/subscriptions","organizations_url":"https://api.github.com/users/joushou/orgs","repos_url":"https://api.github.com/users/joushou/repos","events_url":"https://api.github.com/users/joushou/events{/privacy}","received_events_url":"https://api.github.com/users/joushou/received_events","type":"User","site_admin":false},"created_at":"2016-04-12T17:16:58Z","updated_at":"2016-04-12T17:16:58Z","body":"@weingart I'm not sure I agree that solution 3, in-memory caching, would belong in the file server. One problem I see with this is accept-encoding. I would find storing gzip'd responses to be a high priority, and for this, a higher-level middleware would be required. If you want some rough numbers on why serving gzip'd content cached, in my opinion much more so than serving plain files from cache, see the table at https://kl.wtf/posts/minihttp/ (ignore the 39 seconds run for Caddy, as this is due to excessive GC pressure. With a bigger box, this is the same as \"minihttp, disk, gzip\").\r\n\r\nThe operation of a higher-level middleware would be a bit more complicated. If you are already progressing with injecting correct cache headers, the cache middle-ware would in theory consume these and act as a CDN-style cache proxy. If the cache-header \"generator\" generated a full set of cache-headers, which include different policies for CDN's and client-side caches, then this could in theory work, and would also include the benefit of automatically handling CDN's correctly (which you generally want to cache things differently than the client if there is dynamic content involved).\r\n\r\nAt this level, we would then store a response for each type of Content-Encoding. We could obey Vary to make things fancier, but the problem mainly lies in just having plain and gzip'd content.\r\n\r\nThe alternative would be some potentially complicated rules in a Caddyfile describing cache behaviour. A simple version would be \"cache 2h /blog\", but with dynamic content, these rules might turn less amusing, and partially duplicate the work done to ensure proper cache-headers.\r\n\r\nI personally like the thought of the \"cache-obeying\" variant better, so that cache settings just relate to headers, and middleware will be able to say \"DON'T CACHE THIS\" (dunnnnn dun dun dun...).\r\n\r\nThoughts?"}}