···66Booklet is a simple, global cache optimised for concurrent accesses.
7788Booklets are designed for caching values that persist throughout your program's
99-lifetime. Booklets can never be deleted, but offer thread-safe, atomic updates
1010-and fast concurrent reads.
99+lifetime. Booklets are never automatically deleted or garbage collected. Call `erase`
1010+to reset a booklets' value to its default and remove internal references.
1111+1212+They offer thread-safe, atomic updates and fast concurrent reads.
11131214Booklet is implemented using atomic compare-and-swap operations on top of a
1315managed ETS table on Erlang, or a simple mutable reference on Javascript.
+15-6
src/booklet.gleam
···11/// A Booklet is an opaque, typed reference to a concurrent, atomic, global cache.
22///
33/// Booklets are designed for caching values that persist throughout your program's
44-/// lifetime. Booklets can never be deleted, but offer thread-safe, atomic updates
55-/// and fast concurrent reads.
44+/// lifetime. Booklets are never automatically deleted or garbage collected. Call `erase`
55+/// to reset a booklets' value to its default and remove internal references.
66+///
77+/// They offer thread-safe, atomic updates and fast concurrent reads.
68///
79/// Booklet is implemented using atomic compare-and-swap operations on top of a
810/// managed ETS table on Erlang, or a simple mutable reference on Javascript.
···3537) -> value
36383739/// Atomically replace the value stored in the booklet.
3838-pub fn set(in booklet: Booklet(value), to new_value: value) -> Nil {
3939- update(booklet, fn(_) { new_value })
4040- Nil
4141-}
4040+@external(erlang, "booklet_ffi", "set")
4141+@external(javascript, "./booklet_ffi.mjs", "set")
4242+pub fn set(in booklet: Booklet(value), to new_value: value) -> Nil
4343+4444+/// Erase the value stored in a booklet, resetting it to it's default
4545+/// value provided to `new`.
4646+///
4747+/// On Erlang, this will remove the ETS Table entry.
4848+@external(erlang, "booklet_ffi", "erase")
4949+@external(javascript, "./booklet_ffi.mjs", "erase")
5050+pub fn erase(booklet: Booklet(value)) -> Nil