dgraph-io / ristretto

A high performance memory-bound Go cache
https://dgraph.io/blog/post/introducing-ristretto-high-perf-go-cache/
Apache License 2.0
5.54k stars 364 forks source link

Restrict generic key type to only those supported #371

Closed pete-woods closed 8 months ago

pete-woods commented 8 months ago

Without this, you can specify key types that aren't supported and then have to deal with panics, rather than more pleasant compile-time warnings.

CLAassistant commented 8 months ago

CLA assistant check
All committers have signed the CLA.

CLAassistant commented 8 months ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

mangalaman93 commented 8 months ago

Thanks for the PR. The only problem that I see with this is that any new type addition requires changes to the code and upgrading ristretto.

pete-woods commented 8 months ago

Thanks for the PR. The only problem that I see with this is that any new type addition requires changes to the code and upgrading ristretto.

I believe this is already the case (see linked code): https://github.com/dgraph-io/ristretto/blob/main/z/z.go#L55

Also I put the type next to the key mapping func, so it's clear they both need updating in lockstep.

pete-woods commented 8 months ago

Thanks for your time! 🙇