Comments (14)
@brendanmatkin
Thanks for your valuable information!
As more than one person had asked for the post cacheable feature, we may need to provide a mechanism to make user can define the cacheable logic by himself.
I'm going to think about how to do that in the near feature, and you can make any suggestion at any time.
from axios-extensions.
POST requests are not supported, and I think to fetch data with POST request was not a good idea...
from axios-extensions.
For the sake of discussion:
Technically the HTTP/1.1 RFC document says that POST is a cacheable method: https://tools.ietf.org/html/rfc7231#section-4.2.3.
MDN also says it is cacheable if freshness information is included
: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
In my case I need to send data to be analyzed (as a big JSON) to the server in order to get a response (which can take several minutes to process) - I'd like to cache that response as long as the request body is the same. I don't mind having to manually forceUpdate, but it would be super nice to be able to cache the response to a POST.
It's also possible that this pattern shouldn't be a RESTful interface..
I guess it might be a big change though, since it looks like this library is really structured around GETs and the buildURL helper - how would we handle the POST body if we were to update this project, right?
Anyway I'd like to help but it's a bit over my head. If anyone can give me a few pointers, I can work on it and try to contribute. Thoughts?
from axios-extensions.
@kuitos have a look a cachios, it has a nice implementation of it. mostly due to being able to cache the post request/response with a custom key you want
Good work though!
from axios-extensions.
closed
from axios-extensions.
Hi @kuitos
I think sometimes it makes sense to cache POST requests.
One example I can find is
POST https://graph.microsoft.com/api/beta/me/getMailTips
{
"EmailAddresses": [
"[email protected]",
"[email protected]"
],
"MailTipsOptions": "automaticReplies, mailboxFullStatus"
}
It returns Jack and Rose's mailtip.
BTW, thanks for brining us this library!
from axios-extensions.
This api was served by graphql?
from axios-extensions.
No, it is REST API. Sorry, forget the link. https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/user_getmailtips
from axios-extensions.
@hongbo-miao
Basically POST is not an idempotent operation in semantics. So caching for post request will not be provided imo. See https://stackoverflow.com/questions/626057/is-it-possible-to-cache-post-methods-in-http
from axios-extensions.
@kuitos got it, thank you for the info!
from axios-extensions.
@kuitos ok thanks! I'll chew on it.
For now I'm thinking (since it seems to be needed in only a few edge cases), that checking if the body has changed happens in the implementation (maybe using force-update), and axios-extensions just allows us to use POST as a method. (I guess this is probably what you mean by "define the caceable logic by himself").
This would probably be way easier to build but might lead to some confusion when things are automatically caching even though something has changed... maybe we add another option to flag it as manual caching logic?
from axios-extensions.
@kuitos I feel a generic library like "axios-extensions" should cater to all the methods that axios supports without introducing any subjective presumptions about any methods. It should be on the user to determine which rule of theory they follow. It should let the user choose ingredients of the hash e.g. query, params, body, headers etc. You could just have "cache":true and additional hashing inputs from user.
Doing that would give this library a more generic, free from any assumptions.
from axios-extensions.
POST requests are not supported, and I think to fetch data with POST request was not a good idea...
I've created an package at npm to cache post and get request, just look for axios-post-cache
from axios-extensions.
@brendanmatkin Thanks for your valuable information! As more than one person had asked for the post cacheable feature, we may need to provide a mechanism to make user can define the cacheable logic by himself. I'm going to think about how to do that in the near feature, and you can make any suggestion at any time.
Excuse me, has this function been added?
from axios-extensions.
Related Issues (20)
- Migrate LRUCache to v9.x.x
- axios 1.x has changed axios.defaults.adapter HOT 7
- Source maps reference .ts files
- axios 1.5.0 not compatible HOT 1
- axios-extensions doesn't work with gatsby/webpack due to dependency issue HOT 3
- version 3.1.3 is not es5 compatible because of lru-cache 5.1.1 HOT 3
- Ability to check if response is served from cache
- Invalidate All Cache HOT 3
- Is it possible to save cache in localstorage? HOT 1
- maxAge or throttleAdapterEnhancer HOT 1
- Is it possible to get the network request time that is cached?
- Doesn't work in Vite HOT 1
- ReferenceError: process is not defined HOT 1
- Is it possible to check if request is cached using axios response HOT 1
- Upgrade to LRUCache v7
- Missing source files for sourcemaps? HOT 3
- Warning from deprecated / renamed method in LRUCache HOT 7
- Axios cache just stopped working with today's update - How to solve? HOT 2
- About throttleAdapterEnhancer HOT 2
- Missing "./lib/helpers/buildURL" export in "axios" package HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from axios-extensions.