Netflix / ribbon

Ribbon is a Inter Process Communication (remote procedure calls) library with built in software load balancers. The primary usage model involves REST calls with various serialization scheme support.
Apache License 2.0
4.56k stars 1.24k forks source link

How to PUT values on Cache on the CacheProvider when a miss happens? #263

Open diegopacheco opened 8 years ago

diegopacheco commented 8 years ago

Hi Guys,

/cc @timiblossom @ipapapa @tbak

Im trying to write a driver for dynomite using ribbon and dyno. Something similar to the EVCache ribbon driver but for Dyno/Dynomite. However Im finding issues to figure out where to HOOK the PUT code the update cache after a miss. Even for the EVCache code i was not able to find the PUT to update the cache on the cache miss.

The CacheProvider class just have a get method, do you guys could tell me where to hook this? Or if this is a design design where should i update my cache in case of a miss happens?

Cheers, Diego Pacheco

ipapapa commented 8 years ago

Diego, this is a cool idea. Are you envisioning Ribbon talking to Dyno locally, and then Dyno talking to Dynomite? or Ribbon sending REST calls directly to Dynomite?

diegopacheco commented 8 years ago

@ipapapa @timiblossom @tbak

I Could be wrong but as far as i know this changes are more likely to be into Ribbon rather than in Dyno. Dynomite is awesome solution and looks like a perfect cache for low latency IMHO. I use the Netflix stack already with ribbon so would make more sense to me introduce dynomite as cache through dyno at ribbon level, so would be transparent for the microservices consumers.

We could make ribbon call dynomite via Dyno. That`s what i would like to do. I realize Ribbon has s caching annotation called: com.netflix.ribbon.proxy.annotation.CacheProvider which is a factory and you provide a key + factory(CacheProviderFactory) that creates: CacheProvider.

However com.netflix.ribbon.CacheProvider just have a GET method :( So i don`t see how i can hook a PUT call to Dynomite via Dyno to feed a cache. There is not enough information in context to make the PUT call on the get operation. Since this is build based on a Ribbon Template class here(https://github.com/diegopacheco/netflixoss-pocs/blob/master/ribbon-map-cache/src/main/java/com/github/diegopacheco/netflix/pocs/ribbon/cache/RibbonServiceProxy.java) i would need to know:

Them i would be able to do the call there and feed the cache, this info could be passed to another method something like OnCacheMiss or a updateCache method that`t could receive this info.

Another option would be have the reference of the instance RequestWithMetaData them i would just do: .execute().content() and i would have the ByteBuf in hand i would be happy :-)

You can get all code on this simple project i did here: https://github.com/diegopacheco/netflixoss-pocs/tree/master/ribbon-map-cache (there is no Dyno/Dynomite code here, but has some code using ribbon and show my point with a memory HashMapCache which does not working well because is caching all the time :(. If we have this changes in place it would be easy to replace the HashMap for a Dyno call or something else if someone want it.

Cheers, Diego Pacheco

ipapapa commented 8 years ago

@diegopacheco I had a quick chat with @elandau and he informed me that Ribbon will not be actively developed in the near future. You can see some info #248 . Moreover, my understanding is that the cache you are referring to is a static pre-loaded cache so that is why you can find a PUT call to feed it.

diegopacheco commented 8 years ago

@ipapapa @elandau thanks for the information i was not aware about this.

I will do the cache using Dyno and Dynomite but outside of Ribbon, that`s fine.

Cheers, Diego Pacheco