whitfin / cachex

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

Consider removing `Cachex.count/2` in favour of `Cachex.size/2` #376

Closed whitfin closed 1 month ago

whitfin commented 1 month ago

There are two ways to size your cache:

Even as the author, I totally forgot this and have been using Cachex.size/2 for everything. I think we should:

I think this makes a lot more sense, and is less likely to trip people up. That said, based on the amount of churn turned up in tests here, we might leave this alone...

whitfin commented 1 month ago

I think a better approach here is removing Cachex.count/2 and switching it into an option for Cachex.size/2.

By default Cachex.size/2 will return the total number of records, but you can pass expired: false to disable inclusion of expired records (which defaults to true).

This lessens the surface area of the API, but you don't lose out on functionality. There is therefore also no reason to add anything to Cachex.inspect/2 (which already surfaces the count of expired records, so we have the trifecta now).