Skip to content

raphasampaio/MemoizedSerialization.jl

Repository files navigation

MemoizedSerialization.jl

CI codecov Aqua

Introduction

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.

Features

  • Memoize expensive computations with user-defined keys.
  • Serialize and deserialize results using Serialization.jl.
  • Flexibility to manage paths either implicitly or explicitly.

Getting Started

Installation

pkg> add MemoizedSerialization

Example: @memoized_serialization

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_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)

Example: @memoized_lru

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)

Contributing

Contributions, bug reports, and feature requests are welcome! Feel free to open an issue or submit a pull request.

About

Customizable key-based memoization for caching computations

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •