her icon indicating copy to clipboard operation
her copied to clipboard

Added support of unchanged requests

Open kvokka opened this issue 8 years ago • 6 comments

Added middleware for correct support status 304 in responses

It gives huge speed boost, if you have to

request same resources offten

kvokka avatar Feb 01 '17 19:02 kvokka

Thanks @kvokka - any reason for writing this rather than using the https://github.com/plataformatec/faraday-http-cache gem?

Also, I wonder if you can fix up the failing tests?

edtjones avatar Feb 01 '17 20:02 edtjones

Thank you for so quick response.

gem https://github.com/plataformatec/faraday-http-cache is great, but it targets to client-side optimizing, rather this middleware is targeting to back-end.

This chink was made to prevent heavy response generation on other side, in favor checking updated_at field only, so, 200-500ms sub-requests transformed to 2-5ms.

Travis is green now :)

I've fix syntax to the most common style for Ruby 1.9.3 support. Strange to see 1.9.3 in 2017

kvokka avatar Feb 01 '17 21:02 kvokka

In Caching part of the README shown way, how to implement caching, but, if on other side object will be changed there is no way to get this information. Only expire_in cache, so you will do lots of unneeded expiration's or use stale data. With this middleware there is the way on other side of back-end microservice to know, since what moment the object is fresh.

Of course it is not perfect solution, but it is much more livable, than that, which is included in README.

If you like the code, I can do README update also (or you may take comments from the middleware)

kvokka avatar Feb 02 '17 17:02 kvokka

@kvokka a quick holding message to say I haven't forgotten about this! Just want to find some time to review properly.

edtjones avatar Mar 13 '17 07:03 edtjones

@zacharywelch if you're feeling keen could you review this?

edtjones avatar Jun 02 '17 11:06 edtjones

Hi @kvokka, thanks for the PR! Do you mind putting together some specs describing the middleware behavior? See first_level_parse_json_spec for an example.

I'm also curious what the difference would be with something like faraday-http-cache where it caches api responses and checks whether they're stale on subsequent requests to another microservice or api. Do you have an example you could share?

Another idea discussed in #445 would be to package your own faraday middleware if it's something that could be used by other faraday consumers. Generally her middleware is fundamental to the ORM.

zacharywelch avatar Jun 06 '17 01:06 zacharywelch