lostisland / faraday_middleware

Various Faraday middlewares for Faraday-based API wrappers
MIT License
556 stars 205 forks source link

Add supporting namespace option for cache #282

Closed payk24 closed 2 years ago

payk24 commented 2 years ago

This implementation allows users to use the namespace within the cache store not only for writing but also for reading too.

iMacTia commented 2 years ago

@ipayk thank you for submitting this PR!

TL;DR: Check out faraday-http-cache because I think it might do what you need 🙌!

Longer explanation

As @olleolleolle mentioned above, faraday_middleware is deprecated and we won't be releasing new versions of it. If you would like to make improvements to one of its middleware, we'll first need to create a new "gemified" version of it using faraday-middleware-template and move your PR to that new repository.

You're welcome to do that if you really like this middleware and I'm happy to help if you have any issues, but before that, I just wanted to point out that there's a new community-maintained middleware which I believe is much better than this: faraday-http-cache

My suggestion is to check that out and see if you can use that instead. Since they support ActiveSupport::Cache::Store, you should be already able to use global namespaces!

I'll close this PR because we're not going to merge it anyway, but please let me know what you decide to do 👍

payk24 commented 2 years ago

Hi @iMacTia I know about faraday-http-cache. But unfortunately, there are gems that use this gem (e.g. https://github.com/restforce/restforce) and not faraday 2, and they don't plan to update it yet, which creates a few non-obvious cache problems, as it turns out that it doesn't work.

iMacTia commented 2 years ago

I'm sorry @payk24, I thought I replied to this already but that wasn't the case 🙏.

faraday-http-cache is compatible with Faraday >= 0.8 according to their gemspec, so it should be possible to use it in a project that currently uses faraday_middleware 👍.

As I mentioned, faraday_middleware is deprecated and we're not planning to add any new feature to it. If you'd still prefer to improve and use this middleware, then the other solution is to make a gem out of it using the faraday-middleware-template (let's call it faraday-caching, ideally compatible with both Faraday 1.0 and 2.0), move your changes against that new gem, release it, and use it in your project.

That's how other middleware like faraday-rashify was "gemified" before and they now live as separate repositories that users can use in their projects.