The API request is both post ,I wanna cache the data so as to reduce to load the same data per time.Now I have no idea, pls give me some advices about it .I know I can cache the data if the request is GET....
You can cache the response for any type of request:
Steps are below
First, You has to save response in share instance class.
Whenever you want to hit the API then first check that you have a pre-response that you have saved last in share instance class. If yes then show this response and update response on the success of API. No need to show loading.
Related
I've been told to use POST method to read data instead of the GET method. The tool I'm using is Postman. How can I use POST to fetch data/resources from the server?? I'm testing using any of the testing websites like reqres, gorest, etc.
Tried nothing as of now
Your question isn't really clear but if this api you use exposes a POST method to read data, that means that simply instead of sending a GET request to said URL, you should send a POST http request and the response will be the data you fetched.
On the contrary, if you are composing this api yourself and asking here how to do it, you could simply create a meathod for fetching data and expose this method to a POST request.
I am new in progressive web application and don't know how to cache responses based on the content-type e.g. application/ javascript , image/jpg like this.
I don't want to cache request based on url's i want to cache them using some flag which is available in response headers
How can i check this. Please guide with some code snippet.
Help me out guys...thanks in advance
I found this, we will fetch the request and then get content type from headers and also get flags from response headers and based on these value we can decide whether we need to cache that request or not
my app is a blog. On each blog post page, I make a request to my server to get the relevant data. I'd also like to keep a view count each time the blog page is viewed.
I can do this on the backend when it receives a request. I'm not too sure how cache works in iOS, but my question is, if this data is cached on subsequent views, will this request still be made to the backend on each subsequent view?
Or should I explicitly make a background request in my ViewController to update the view count tally?
If you are using URLRequest to call your API, then you can set the cachePolicy so that if your backend responds with the correct caching headers then if nothing has changed it won't reload.
You may want to re-architect your API so that you don't have to load the whole blog post every time just to update the view count. Perhaps that should be a separate API call, which has its own caching policy (since it changes more frequently)
I'm curious about NSURLCache, NSURLRequest has some policy of cache,
like NSURLRequestUseProtocolCachePolicy, NSURLRequestReturnCacheDataElseLoad,
but after read them, either of them are using local cache data, or not using cache,
My question is if I want start a url request, first I wanna load cache and render ui, then continue interacting with server to grab latest data and refresh the ui, which policy is my choice?
If I understand correctly what you want to achieve (get data quickly from the cache to show in the UI even if it is outdated, then get the current data even if it is slow), you'd have to make two requests, using different cache policies. I'd start the second request only when the first one has finished, and examine the result of the first request first, because the data might not have been available in the cache, so the first request might already returned the uncached data that you wanted.
I'm just starting out to use the Parse API and I am going to, among other things, use it to store some static data that my iOS apps will occasionally download. I do, however, have a need to occasionally update this static data, but Parse isn't very clear on how to update that data once it is initially uploaded.
Parse's API docs show you how to upload files of the same name without overwriting existing data, but in this case that's exactly what I want to do. How do I upload updates to the same file?
In this case I am using the REST API to upload the content. I get the URL back to reach the content, but I am not able to update it by simply POSTing to the URL that it returns. I get a 405 denied. I try changing the HTTP method to PUT, but that results in a 403 Unauthorized.
You can upload a new file, then update the Parse object with a reference to the new file. Each file gets its own unique permalink, so they cannot be "updated" with new content.
However you can update any object to point to the new file.
Turns out that you cannot update a static resource, but upload a new one. This turns out to be four API calls:
Upload resource
Get File object
Update pointer
Delete old resource
Then for a client:
Get File object
Download static resource