Skip to content

[BUG] cache.Handler doesn't distinguish between methods on same path #1621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AlbinoGeek opened this issue Sep 10, 2020 · 1 comment
Closed

Comments

@AlbinoGeek
Copy link

Summary

cache.Handler(time.Minute) meant a POSTed Contact Form returned the empty/unfilled GET handler from cache!

The POST handler was not executed, if the GET handler has been reached within the same cache time (Minute)

Versions, etc.

Thing Version
Golang 1.14.7 linux/amd64
Iris master 333be42
Kernel 5.8.4-200.fc32.x86_64
OS Fedora 32 Workstation

Console Output

[INFO] 2020/09/10 07:18 200 239.519µs [REDACTED] POST /contact
#    ------------------ ^^^
#    should have been a 500 if the POST handler was executed

Code

func (c *PublicController) BeforeActivation(b mvc.BeforeActivation) {
	b.Router().Use(cache.Handler(time.Minute))
}

func (c *PublicController) GetContact(ctx iris.Context) mvc.Result {
	golog.Warn("Sanity Check: This is the GET Handler")
	return mvc.View{
		Code: iris.StatusOK,
		Name: "contact.html",
	}
}

func (c *PublicController) PostContact(ctx iris.Context) mvc.Result {
	golog.Warn("Sanity Check: This is the POST Handler")
	return mvc.View{
		Code: iris.StatusInternalServerError,
		Text: "It's a bug if you DON'T see this.",
	}
}
@kataras
Copy link
Owner

kataras commented Sep 10, 2020

Oh thanks @AlbinoGeek, this is fixed now. Also, now you have the ability to set the cache entry key/identifier with cache.WithKey(string) iris.Handler (use as middleware) or cache/client.SetKey(iris.Context, string). Example has been updated too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants