cJsonHttpTransfer - Cache?
Hi everyone,
I have the following issue:
I use a cHttpTransfer-Object to make a call to an API. Each call to the API should return different results.
The "HttpGetRequest" can be executed multiple times, but the server only receives the first request. All subsequent calls to the function return the same response and no more calls to the server are made.
This happens even if I destroy the oHttpTransfer-Object.
If I append a random url-parameter to the url and change it every time I make the call, it works. I suspect there is something wrong with the implementation of one of the base classes in the framework (or in the way I use them ;)).
Regards
Raphael
Re: cJsonHttpTransfer - Cache?
[COLOR=#333333][quote]If I append a random url-parameter to the url and change it every time I make the call, it works[/quote]
This is a standard technique used by the internet in general to get over browser or any other proxy cache between the client and the server[/COLOR]
Re: cJsonHttpTransfer - Cache?
I don't have a cache/proxy between the client and the server and I destroy the client-object (so a local cache should be deleted as well). Also: If I open it in the browser (with cache and everything enabled) it reloads with different data every time.
Re: cJsonHttpTransfer - Cache?
Hi Raphael,
I read somewhere the other day (Hi Mike) that caching is a feature for a RESTful API.
You might want to try adding a pragma: no-cache header to see if that helps.
See also:
[url]https://www.apiacademy.co/articles/2015/12/how-to-http-caching-for-restful-hypermedia-apis[/url]
--
Wil
Re: cJsonHttpTransfer - Cache?
Btw. The same thing happens if you open the DataFlex Studio and import a Client WebService with a WSDL file... If the WSDL changes and you want to reimport it, you have to completly close the DataFlex Studio in order to reimport the changed version of the Webservice/WSDL-file (or append some random parameter).
Re: cJsonHttpTransfer - Cache?
Raphael,
I ran into this a while back ago and I ended up sending 'ClearHeaders' to the cHttpTransfer object prior to each call. Seems to work for me.
Hope this helps,
Jeff
Re: cJsonHttpTransfer - Cache?
havent done this with DF but normally you would add the following header
Cache-Control: no-chache
Re: cJsonHttpTransfer - Cache?
hold on you are talking about the client call.
the cache setting should be made on the server in the API
Re: cJsonHttpTransfer - Cache?
looks like it should work from the request as well
[COLOR=#000000][FONT=&]Common Cache-Control directives are shown in the following table.[/FONT][/COLOR]
[COLOR=#000000][FONT=&][TABLE="width: 940"]
[TR]
[TH="class: x-hidden-focus, align: left"]Directive[/TH]
[TH="align: left"]Action[/TH]
[/TR]
[TR]
[TD][URL="https://tools.ietf.org/html/rfc7234#section-5.2.2.5"]public[/URL][/TD]
[TD]A cache may store the response.[/TD]
[/TR]
[TR]
[TD][URL="https://tools.ietf.org/html/rfc7234#section-5.2.2.6"]private[/URL][/TD]
[TD="class: x-hidden-focus"]The response must not be stored by a shared cache. A private cache may store and reuse the response.[/TD]
[/TR]
[TR]
[TD][URL="https://tools.ietf.org/html/rfc7234#section-5.2.1.1"]max-age[/URL][/TD]
[TD="class: x-hidden-focus"]The client doesn't accept a response whose age is greater than the specified number of seconds. Examples: max-age=60 (60 seconds), max-age=2592000 (1 month)[/TD]
[/TR]
[TR]
[TD][URL="https://tools.ietf.org/html/rfc7234#section-5.2.1.4"]no-cache[/URL][/TD]
[TD="class: x-hidden-focus"][B]On requests[/B]: A cache must not use a stored response to satisfy the request. The origin server regenerates the response for the client, and the middleware updates the stored response in its cache.
[B]On responses[/B]: The response must not be used for a subsequent request without validation on the origin server.[/TD]
[/TR]
[TR]
[TD][URL="https://tools.ietf.org/html/rfc7234#section-5.2.1.5"]no-store[/URL][/TD]
[TD="class: x-hidden-focus"][B]On requests[/B]: A cache must not store the request.
[B]On responses[/B]: A cache must not store any part of the response.[/TD]
[/TR]
[/TABLE]
[/FONT][/COLOR]
[COLOR=#000000][FONT=&]Other cache headers that play a role in caching are shown in the following table.[/FONT][/COLOR]
[COLOR=#000000][FONT=&][TABLE="width: 940"]
[TR]
[TH="align: left"]Header[/TH]
[TH="align: left"]Function[/TH]
[/TR]
[TR]
[TD][URL="https://tools.ietf.org/html/rfc7234#section-5.1"]Age[/URL][/TD]
[TD]An estimate of the amount of time in seconds since the response was generated or successfully validated at the origin server.[/TD]
[/TR]
[TR]
[TD][URL="https://tools.ietf.org/html/rfc7234#section-5.3"]Expires[/URL][/TD]
[TD]The time after which the response is considered stale.[/TD]
[/TR]
[TR]
[TD][URL="https://tools.ietf.org/html/rfc7234#section-5.4"]Pragma[/URL][/TD]
[TD]Exists for backwards compatibility with HTTP/1.0 caches for setting no-cache behavior. If the Cache-Control header is present, the Pragma header is ignored.[/TD]
[/TR]
[TR]
[TD][URL="https://tools.ietf.org/html/rfc7231#section-7.1.4"]Vary[/URL][/TD]
[TD]Specifies that a cached response must not be sent unless all of the Vary header fields match in both the cached response's original request and the new request.[/TD]
[/TR]
[/TABLE]
[/FONT][/COLOR]
Re: cJsonHttpTransfer - Cache?
Calling "Send destroy of ..." and creating a new object should do the trick as well, right? The interesting part (for me) is that the http-request is only made once, until I restart the application, even though I destroy and recreate the httptransfer-object.