eko / gocache

☔️ A complete Go cache library that brings you multiple ways of managing your caches
https://vincent.composieux.fr/article/i-wrote-gocache-a-complete-and-extensible-go-cache-library/
MIT License
2.46k stars 195 forks source link

Suggestion for an easier interface #167

Closed mikestefanello closed 1 year ago

mikestefanello commented 2 years ago

I wrote and maintain pagoda, a rapid, full-stack web development starter kit. I included gocache to provide a flexible way to handle caching that wouldn't have to be changed if you opt for a different cache provider. While I think this module is great, I found the interface to be somewhat cumbersome to deal with so I wrote a wrapper on top of it that I think turned out pretty well. Since this is something I'd like available in other projects, I thought I'd see if it's something you'd be interested in bringing in.

Here is the overall explanation of how it works and what is available. And here is the client code that provides that.

For quick reference, here is an example:

err := cache.
    Set().
    Key("my-key").
    Tags("tag1", "tag2").
    Expiration(time.Hour * 2).
    Data(myData).
    Save(ctx)
eko commented 1 year ago

Hello @mikestefanello,

Thank you for your feedback, I like your approach but I think it would be strange to implement a second way of dealing with objects into gocache.

I prefer to let developers implement their own wrapper as you made if you want another way of chaining methods.

Closing this issue for now but feel free to open if you have any issue with existing interface.