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

Add clause to Cachex.unwrap_unsafe/1 to allow unwrapping calls to Cac… #379

Closed HansGlimmerfors closed 1 month ago

HansGlimmerfors commented 1 month ago

…hex.fetch!/4 when options are provided

doctest from cachex.ex:

iex> Cachex.fetch(:my_cache, "missing_key_expires", fn(key) ->
...>   { :commit, String.reverse(key), expire: :timer.seconds(60) }
...> end)
{ :commit, "seripxe_yek_gnissim", [expire: 60000] }

The unsafe version Cachex.fetch!/4 will fail when providing options as in the example above due to a FunctionClauseError. This PR adds the missing function clause.

whitfin commented 1 month ago

You know, I thought more about this and this is actually a bug in the first place; it shouldn't be returning the options.

I've fixed it over here, but thank you very much for your contribution and raising this as an issue!