new feature: Add cache layer for opendal
Provide high-quality built-in cache support in OpenDAL while ensuring users have the flexibility to implement their own caching logic.
Hi, I would like to work on this, can I? Or is anybody willing to work on this already?
I thought about using https://github.com/foyer-rs/foyer. I see It has been already discussed here.
Hi, @jorgehermo9, that will be greatly appreciated. No one is currently working on this.
Ideally, our cache layer should enable users to design and implement their own cache algorithms while seamlessly switching between different cache crates like Foyer or Moka. However, I believe we should integrate with Foyer first to clarify our direction moving forward.
Let's first build a FoyerLayer, and later, we can extract a CacheLayer from it.
I agree a lot with the plan!! Thanks @xuanwo š
Just as an update about this, I have the initial implementation almost finished (for read and blocking_read operations for the moment) and will submit a PR in a few days/a week, as soon as I can š
I have an idea that our future CacheLayer can accept an Operator instead. Take foyer as an example, we can implement a foyer service. And use it like:
let cache_op = Operator::from_config(FoyerConfig::default).finish()?;
let op = op.layer(CacheLayer::new(cache_op));
We will need a benchmark to evaluate their performance.
I am currently trying to write this CacheLayer (to be used in some multi-layer caching scenarios, such as memory + redis). I might consider submitting a draft PR later this week to discuss some implementation details.
In fact, I have implemented a simple cache layer, customized the cache logic through a CacheStorage trait, and implemented this trait for Operator, now we can build an operator with a cache layer in the following way:
let moka_builder = <MokaBuilder>::default().name("demo1").time_to_live(Duration::from_secs(1));
let moka1 = Operator::new(moka_builder)?.layer(LoggingLayer::default()).finish();
let moka_builder = <MokaBuilder>::default().name("demo2").time_to_live(Duration::from_secs(5));
let moka2 = Operator::new(moka_builder)?.layer(LoggingLayer::default()).finish();
let op = Operator::new(NoopBuilder)?
.layer(CacheLayer::new(moka2))
.layer(CacheLayer::new(moka1))
.finish();
I am currently trying to write this CacheLayer (to be used in some multi-layer caching scenarios, such as memory + redis). I might consider submitting a draft PR later this week to discuss some implementation details.
Hi, I'd prefer if we could have an RFC first before getting into implementation details. I'm not sure we're on the same page yet.
By the way, @MrCroxx is also working this. Maybe we can have a small talk around it.
Hi @xuanwo, do you expect me to continue in my foyer implementation PR or should I it hand off to @MrCroxx's work?
I mean, if my PR was not what you expected, I could stop working on it
Hi, I'd prefer if we could have an RFC first before getting into implementation details. I'm not sure we're on the same page yet.
By the way, @MrCroxx is also working this. Maybe we can have a small talk around it.
This PR is just a prototype (mainly used to discuss some designs, not the final implementation), I will also consider writing a related RFC (maybe after some discussion?)
Iād be happy to have a small talk about it.
Hi @Xuanwo, do you expect me to continue in my foyer implementation PR or should I it hand off to @MrCroxx's work?
I mean, if my PR was not what you expected, I could stop working on it
Thank you for your experiment! I think we shouldn't have a foyer layer. Instead, we should have a cache layer along with a foyer service. Are you interested in updating your PR to implement a foyer service instead?
No problem @Xuanwo, I think you are right and I have the same opinion about this.
Are you interested in updating your PR to implement a foyer service instead?
I don't think there is anything on that PR that we can reuse for the service... I think it would be better to start from scratch though, I can't confirm if I have enough time to work on that also! Feel free to close the PR if you want
I don't think there is anything on that PR that we can reuse for the service... I think it would be better to start from scratch though, I can't confirm if I have enough time to work on that also! Feel free to close the PR if you want
Sorry about this. I have learned, experimented, and thought a lot based on your PR. If there is anything that makes the opendal cache layer looks great, your contribution is definitely the most important.
I will find other ways to recognize your contribution, even if it can't be merged as a dedicated PR.
dont apoligize @xuanwo! I also learned a lot while working on it. Thank you very much for your kind words :)
I've proposed a new RFC for the cache layer, and I'd appreciate if you could give me some feedback, this is my first time proposing an RFC so I don't know if there's anything I did wrong :P