local-ch / lhc

🚀 Advanced HTTP Client for Ruby. Fueled with interceptors.
GNU General Public License v3.0
43 stars 1 forks source link

Adding multi-level cache to caching interceptor #188

Closed 10xSebastian closed 4 years ago

10xSebastian commented 4 years ago

This adds the possibility to configure multi-level (local & central) caching for the caching interceptor.

Also:

Caching Interceptor

You can also use a central http cache to be used by the LHC::Caching interceptor.

If you configure a local and a central cache, LHC will perform multi-level-caching. LHC will try to retrieve cached information first from the central, in case of a miss from the local cache, while writing back into both.

  LHC::Caching.central = {
    read: 'redis://$PASSWORD@central-http-cache-replica.namespace:6379/0',
    write: 'redis://$PASSWORD@central-http-cache-master.namespace:6379/0'
  }
10xSebastian commented 4 years ago

@christianarevalo

Right now no matter if local cache or central cache, both apply the same provided cache options, as the same caching options apply to a multilevel cache. A multilevel cache is consider 1 cache from a client perspective, just stored on multiple level, following the same options (like expiry).

e.g.

cache: { expires_in: 1.day }

That would make both cache layers expire after 1 day.

For invalidating targeted records, we would still need to implement invalidation services (like for customers etc.). but that's not part of an http client nor interceptor implementation, but rather a dedicated service implementation.