This namespace custom freeze/thaw implementations that allow Clojure fns to be serialized with all the standard Nippy freeze/thaw fns.
Only a fn's internal class name and the objects in the closure are actually serialized. No code or bytecode is serialized. Both the freezing process and the thawing process must be running the same code, or the thaw operation can have undefined behavior.
A custom serializer / deserializer for each frozen/thawed fn type is generated
upon first use, and then cached for future access, making it very efficient.
(No reflection is required during steady state operation.) The cache can be
cleared via the clear-cache
fn; you typically only need to do this during
interactive development.
To use this extension, just define fns like usual and then freeze instances to bytes:
(let [d 10 my-fn (fn [a b c] (+ a b c d))] (nippy/freeze! my-fn) ; => bytes )
The same instances can be thawed again later, and will reconstruct its closure as expected:
(let [d 10 my-fn (fn [a b c] (+ a b c d)) frozen-fn-bytes (nippy/freeze! my-fn) thawed-fn (nippy/thaw! frozen-fn-bytes)] (thawed-fn 1 2 3); => 16 )
Be careful about freezing fns that have 'big' stuff in their closure! All referenced objects will be recursively serialized. If an un-freezeable object is encountered, then it will cause an error.
This namespace custom freeze/thaw implementations that allow Clojure fns to be serialized with all the standard Nippy freeze/thaw fns. Only a fn's internal class name and the objects in the closure are actually serialized. No code or bytecode is serialized. Both the freezing process and the thawing process must be running the same code, or the thaw operation can have undefined behavior. A custom serializer / deserializer for each frozen/thawed fn type is generated upon first use, and then cached for future access, making it very efficient. (No reflection is required during steady state operation.) The cache can be cleared via the `clear-cache` fn; you typically only need to do this during interactive development. To use this extension, just define fns like usual and then freeze instances to bytes: `(let [d 10 my-fn (fn [a b c] (+ a b c d))] (nippy/freeze! my-fn) ; => bytes )` The same instances can be thawed again later, and will reconstruct its closure as expected: `(let [d 10 my-fn (fn [a b c] (+ a b c d)) frozen-fn-bytes (nippy/freeze! my-fn) thawed-fn (nippy/thaw! frozen-fn-bytes)] (thawed-fn 1 2 3); => 16 )` Be careful about freezing fns that have 'big' stuff in their closure! All referenced objects will be recursively serialized. If an un-freezeable object is encountered, then it will cause an error.
(clear-cache)
Clear all cached generated serializer and deserializer fns. You typically only need to do this if you've redefined a fn to include new vars in its closure during interactive development.
Clear all cached generated serializer and deserializer fns. You typically only need to do this if you've redefined a fn to include new vars in its closure during interactive development.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close