FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Publish caddy-cache by nicolasazrak · Pull Request #1759 · caddyserver/caddy · GitHub

Repository navigation

Publish caddy-cache - #1759

Merged
mholt merged 1 commit into
caddyserver:masterfrom
nicolasazrak:master
Jul 13, 2017
Merged

mholt merged 1 commit into
caddyserver:masterfrom
nicolasazrak:master

Conversation

Copy link
Copy Markdown

After a long time I finally think caddy-cache is ready to be published. It does not have every feature I want but I think it handles the basic thinks it needs to support:

  • it handles Vary header
  • it handles correct usage of cache headers with the help of https://github.com/pquerna/cachecontrol
  • it handles locking and concurrency (if two request gets the server at the same time, there will be only one fetch to upstream and both original requests will get the response at the same time without having to wait until the upstream request ends)

What do you think?

1. What does this change do, exactly?

Adds a middleware for http caching

2. Please link to the relevant issues.

#10

3. Which documentation changes (if any) need to be made because of this PR?

It needs a new section for the new cache directive

4. Checklist

  • I have written tests and verified that they fail without my change
  • I have squashed any insignificant commits
  • This change has comments for package types, values, functions, and non-obvious lines of code
  • I am willing to help maintain this change if there are issues with it later

CLAassistant commented Jul 12, 2017 •
edited
Loading

Copy link
Copy Markdown


All committers have signed the CLA.

tobya commented Jul 12, 2017

Copy link
Copy Markdown
Contributor

@nicolasazrak thanks for the PR and the great looking plugin.

Does the cache directive need to be the first plugin? Perhaps if it does you could provide a little explanation, and if not perhaps move it further down the list close to realip and git.

Comment thread caddy/caddymain/run.go Outdated
"github.com/mholt/caddy/caddytls"
// This is where other plugins get plugged in (imported)

_ "github.com/nicolasazrak/caddy-cache"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please remove this

nicolasazrak force-pushed the master branch 2 times, most recently from 50eb8ec to a8c2e1a Compare July 12, 2017 14:11

nicolasazrak commented Jul 12, 2017 •
edited
Loading

Copy link
Copy Markdown
Author

@tobya I think I am a little confused about how root works. I expected root to be one of the last ones, so other plugins like gzip had the chance to intercept the content root writes and do something, but I moved cache after git and it seems to be working.

mholt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm really excited to get this plugin in the next release of Caddy. Thanks for working on it! It will help a lot of people!

Comment thread caddyhttp/httpserver/plugin.go Outdated
"realip", // github.com/captncraig/caddy-realip
"git", // github.com/abiosoft/caddy-git

"cache",

mholt Jul 12, 2017 •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm not convinced this is the right place for this directive in the middleware chain. This list is the order in which middlewares are executed: both during set up and during actual request-time (if they inject handlers).

First things first: to keep track of which directives are third-party plugins, please add a comment to this line with the path to your cache package (as you can see on many of the other lines, sorry if it wasn't explicit in the wiki). // github.com/nicolasazrak/caddy-cache

Next, I think we should move it lower in the list... at least probably not "on its own" like this. I wouldn't know for sure where it belongs, but typically you'll want handlers to go as late in the middleware chain as is possible while having it still work properly. If your handler terminates the chain by serving the response, then the request will never see the rewrite handler, which might break things if people are using it to rewrite URIs. It also comes before the errors directive. Most middleware will want to come after that so that errors returned by your handler can be properly handled. But then again, I don't know for sure in the case of a cache middleware... if you cache the error pages too, then maybe it doesn't matter? (Maybe cache belongs a little lower at least, like where the handler directives are.)

Anyway, I hope that makes sense. If you're unsure, try testing with a few of the directives to see if your cache behaves the way you expect. If not, make sure to move it lower in the chain.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

After looking the order for a while I cannot find the correct place. I think it should be after log and errors but it also should be before gzip and maybe even before ratelimit, but errors is after gzip.

Although being after gzip (or minify) will work, caching gzipped responses can save a lot of cpu. As cache goes lower in the list, more duplicated tasks will be made, defeating the cache purpose which is avoid them. Maybe moving errors after log and putting cache after (log -> error -> cache) would solve the issue.

Being before rewrite should not be a problem because given an request url the rewrite should be the same and caching still applies.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

If being lower in the list will not serve its purpose well, then it's okay to keep it higher. I can definitely understand wanting to keep it above gzip so you can cache compressed responses where clients accept the same encoding.

As long as URL rewrites don't ever have a 1:many mapping, putting cache before rewrite should be fine.

Just don't put it in its own space. ;) The whitespace (empty lines) seem to signal that cache is on its own and I think it's best if it fits in as close as it can with existing groups.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

(To clarify/summarize, in case I wasn't clear: go ahead and leave it where it is, if you think this is best, just put it in the last big group with the others, rather than off by its own.)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I will leave it after log (without whitespace). Is it ok moving errors after log? So cache errors can be handled. The only problem I see is that error pages will not be compressed, but that should not be a big problem.

About rewrite having 1:many mapping, in that case rewrite should add Vary header to inform that depending on some header the response could change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

No, don't reorder any of the other directives. Just leave cache where it best belongs, which after your investigation, is apparently in this place. Just remove the whitespace so it fits in the group. Thanks!

mholt commented Jul 13, 2017

Copy link
Copy Markdown
Member

Waiting for @elcore to approve and then will merge. 👍 Thank you, Nicolas! You can publish your plugin immediately after the next release of Caddy. If it needs to be re-ordered in this list, you can do so most efficiently before that release. 😉

Copy link
Copy Markdown
Author

@mholt thanks I'll be waiting for the next release !

mholt merged commit ba11322 into caddyserver:master Jul 13, 2017
mholt modified the milestone: 0.10.5 Jul 14, 2017

mholt commented Jul 27, 2017

Copy link
Copy Markdown
Member

@nicolasazrak The new version is out, you may now publish this plugin!

Copy link
Copy Markdown
Author

@mholt it's done ! 🎉

mholt commented Apr 1, 2020

Copy link
Copy Markdown
Member

@nicolasazrak If you'd ever be interested in helping to build the v2 equivalent of a caching middleware, we have a repo for it now: https://github.com/caddyserver/cache-handler - just FYI, you're not obligated or anything :)

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL