pointfreeco / swift-composable-architecture

A library for building applications in a consistent and understandable way, with composition, testing, and ergonomics in mind.
https://www.pointfree.co/collections/composable-architecture
MIT License
12.22k stars 1.42k forks source link

Add support for custom decoding/encoding to `fileStorage` #3225

Closed oskarek closed 1 month ago

oskarek commented 2 months ago

This PR generalizes the fileStorage persistence key so that it can be used with values that are not Codable, by adding the ability to provide custom decode/encode closures as parameters. Also, for Codable values, the json decoder/encoder can now be customized.

Alex293 commented 2 months ago

I had a recent need to do some cache validation before retrieving the value (drop the file if it was created before some date). I wonder if instead of just focusing on codable this should go as far for loading/writing from/to URL.

I'd love to ear about how to make a composable wrapper to handle caching too

stephencelis commented 2 months ago

@oskarek Thanks for taking the time to PR! We do think that supporting more than JSON is a good idea but haven't had time to review yet and think about the API. Hopefully soon!