Hi Guys,
I'm looking for a tiny cache library. Basically I need storage some keys (without a lot complexity) I comes across with this project[1] but I would like to know if other folks can suggest a new ones different based on their own experience.
(I know I can write a new library, but I don't need reinventing the wheel)
[1] https://github.com/patrickmn/go-cache
评论:
dgryski:
deivinsontejeda:All caching algorithms have different tradeoffs in terms of speed and expiration accuracy. Your post doesn't give enough details on your workloads. Depending on the recomputation cost, even something like random eviction can be sufficient and has the advantage of a very simple implementation: https://github.com/dgryski/trifles/blob/master/cachetest/random/random.go .
dgryski:Sure, I wasn't enough clear about what it's my current case.
I have a microservice which focus on serving files. These file live in different provider (AWS, Azure and so on) I want to avoid hit everytime AWS or Azure for the same object (these objects are Pre-Signed URL).
It's very simple just fetch first time the URL and sub-secuent request return cached data instead of hit external API.
deivinsontejeda:So how effective does your cache hit ratio need to be? How expensive is a cache miss? Can you just store all the queries? How big is the working set compared to what you can store and how big the total collection is?
My suggestion is still to start with something dumb and measure the effectiveness. Bonus points if you have a query trace you can use to simulate different caches with to see which one matches best. (But really, anything above a simple LRU is just small incremental improvements in cache hit ratio.
deivinsontejeda:Awesome, thanks!
seankhliao:I ended up writting a little interface using code share and tracking some info in order to get much more details about what exactly I need build.
This is like you suggested to me: a dumb implementation and tuning it given data analyze.
konart:What's wrong with a simple map?
albatr0s:More like sync.Map, I guess.
Anyway - you'd have to write all the logic by your self. How big can your cache grow, how to clean it etc.
NovaX:
dametsumari:
I have been happy with https://github.com/bluele/gcache - although am considering writing my own, as I dislike interface{} using interfaces as they potentially break if and when I fumble wrong types around :-p
