Skip to content
This repository has been archived by the owner on Dec 20, 2020. It is now read-only.

Case cache option in POST requests #7

Closed
foxbunny opened this issue Jan 28, 2014 · 12 comments
Closed

Case cache option in POST requests #7

foxbunny opened this issue Jan 28, 2014 · 12 comments

Comments

@foxbunny
Copy link
Contributor

Is there any use case for cache option in POST requests? If not, then I suggest the default value of cache option to depend on method name, where it would be false by default on GET requests, and true for POST. I'll do a PR so you can see what I mean.

@pyrsmk
Copy link
Owner

pyrsmk commented Jan 28, 2014

I think POST requests can return different responses and they can handle a lot of request types with the _METHOD attribute that is used in some frameworks, as PUT, DELETE and other manual types. Caching POST requests shouldn't affect normal behavior of an application?

@foxbunny
Copy link
Contributor Author

I don't think it does, but I also think it's unnecessary, and having true as default for POST is reasonable.

POST requests aren't meant to be cached under normal circumstances, and browsers won't cache it, so there's no need for cache-busting. Same applies for all simulated verbs which are using POST behind the scenes with more or less similar semantic in terms of cache-ability.

@pyrsmk
Copy link
Owner

pyrsmk commented Jan 29, 2014

Ok, then I'm agree with your changes. Just one thing, at line 248, your line should be :

if(cache === null){ cache = method=='POST'; }

Otherwise if cache is false then your condition will override the value.

@foxbunny
Copy link
Contributor Author

You're rigth. But let's make that:

if (typeof cache == 'undefined' || cache === null){ cache = method=='POST'; }

@foxbunny
Copy link
Contributor Author

Actually. Hm. No, leave it as it is in my original pull. false == null is never true.

EDIT:

Just tested in most of the browsers I have + NodeJS.

Using double-equals with null will be true only for undefined and null itself.

@pyrsmk
Copy link
Owner

pyrsmk commented Jan 29, 2014

Yep, I just saw on MDN that null is seen as an object by typeof. But, if cache is undefined, is it considered as null?

@foxbunny
Copy link
Contributor Author

Here's a console session to prove it works:

false == null
false
null == null # This is what we want
true
undefined == null # And this
true
0 == null
false
'' == null
false
'null' == null
false

@foxbunny
Copy link
Contributor Author

FYI, CoffeeScript and similar languages almost universally use the == null technique to test if something is undefined or null, so I think it's safe to use. I use it all the time because I use Coffee/LiveScript and it's never lead to weird unexpected behavior.

@pyrsmk
Copy link
Owner

pyrsmk commented Jan 29, 2014

Interesting! Fine, let's do that PR ^^

@pyrsmk pyrsmk closed this as completed Jan 29, 2014
pyrsmk pushed a commit that referenced this issue Jan 29, 2014
Fixes #7: Caching only disabled in GET requests
@pyrsmk
Copy link
Owner

pyrsmk commented Jan 29, 2014

And thanks a lot for your help ;)

@foxbunny
Copy link
Contributor Author

Just scratching my own itch. :)

@pyrsmk
Copy link
Owner

pyrsmk commented Aug 13, 2015

It seems apache does not support POST requests caching. Then, cache option is now disabled for all requests.

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

No branches or pull requests

2 participants