whitfin / cachex

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

Test new approaches for persisting caches to disk #365

Closed whitfin closed 4 days ago

whitfin commented 5 days ago

The current approach requires loading a full cache and exporting an entire cache via Erlang terms. We should see if we can do something to improve this, such as streamed input.

If this isn't possible, it's not the end of the world, just want to take a look and see if we can do better.

whitfin commented 5 days ago

I tested some approaches, and I think I will do a lot of changes here for v4.x.

I think Cachex.import/3 can stay as is, although it should accept a stream of records as well. There's potential to simply remove Cachex.export/2 but keeping it as a grace function is probably fine.

The result of all of this is that we're reusing common foundations in the implementations, and we're much lower on memory. Performance is a little slower, but we gain memory safety and we also get the ability to export based on a query, which is pretty cool.