MemoizedSerialization.jl is a Julia package that provides macros for memoizing the results of function calls using Serialization.jl. This is particularly useful for expensive computations with non-hashable arguments, as it allows the user to define custom keys for memoization. This package allows you to persist the results of function calls and retrieve them from disk if they have been previously computed, saving time for repeated evaluations.
- Memoize expensive computations with user-defined keys.
- Serialize and deserialize results using Serialization.jl.
- Flexibility to manage paths either implicitly or explicitly.
pkg> add MemoizedSerializationusing MemoizedSerialization
function sum(a, b)
println("Computing sum($a, $b)")
return a + b
end
# first call with (1, 2) - computation is performed and result is serialized
a, b = 1, 2
result = @memoized_serialization "sum-$a-$b" sum(a, b)
# second call with (2, 2) - computation is performed and result is serialized
a, b = 2, 2
result = @memoized_serialization "sum-$a-$b" sum(a, b)
# third call with (1, 2) - result is loaded from cache (deserialized)
a, b = 1, 2
result = @memoized_serialization "sum-$a-$b" sum(a, b)using MemoizedSerialization
function sum(a, b)
println("Computing sum($a, $b)")
return a + b
end
# first call with (1, 2) - computation is performed and result is serialized
a, b = 1, 2
result = @memoized_lru "sum-$a-$b" sum(a, b)
# second call with (2, 2) - computation is performed and result is serialized
a, b = 2, 2
result = @memoized_lru "sum-$a-$b" sum(a, b)
# third call with (1, 2) - result is loaded from cache (deserialized)
a, b = 1, 2
result = @memoized_lru "sum-$a-$b" sum(a, b)Contributions, bug reports, and feature requests are welcome! Feel free to open an issue or submit a pull request.