whitfin / cachex

A powerful caching library for Elixir with support for transactions, fallbacks and expirations
https://hexdocs.pm/cachex/
MIT License
1.59k stars 101 forks source link

Document that keys must implement `String.Chars` when using `Cachex.Router.Ring` #386

Open probably-not opened 5 hours ago

probably-not commented 5 hours ago

The specs for all of the Cachex functions all specify that the key is an any(), however, when using the Cachex.Router.Ring router module (which seems to be recommended in the latest docs), the key is actually required to be a ExHashRing.Hash.hashable(), which is essentially an alias for String.Chars.t().

whitfin commented 5 hours ago

Yeah, you're not wrong!

I guess I'm not entirely sure on the best approach here, because routers are third-party pluggable, and I can't control their types. So by that logic Cachex's main interface can't do much beyond any(); is it sufficient to add ExHashRing.Hash.hashable() to the typing on the router implementation itself?

I assume you found this via some type checking utility, would this work for that case?