ANN: Scratch.jl -- package specific mutable data containers

Scratch.jl

Scratch.jl implements package-specific namespaced mutable data scratch spaces/containers. The spaces can contain datasets, text, binaries, or any other data that is convenient to store in a package-specific location. Scratch spaces are designed for data caches that are completely managed by a package and should be removed when the package itself is uninstalled. In the current implementation, scratch spaces are removed during Pkg garbage collection if the owning package has been removed.

The basic usage consists of the @get_scratch! macro, which is used as follows

julia> dir = @get_scratch!("container-key")
"/home/fredrik/.julia/scratchspaces/6c6a2e73-6563-6170-7368-637461726353/container-key"

As you can see from the returned path, the container is namespaced with the package UUID (Scratch.jl’s UUID in this case). This directory now exists, and is writeable for the package to use.

Scratch.jl keeps track of the usage, and Pkg’s garbage collection deletes the containers, together with the owning package, when it is no longer beeing used.

Please see the README file for more details and more examples, and please open an issue ticket if you run into any problems.

Compatibility disclaimer

The package is tested and works correctly with Julia 1.5, however, Pkg’s built-in garbage collection, i.e. Pkg.gc(), is only aware of scratchspaces for Julia 1.6 and beyond. This means that scratch spaces will continue to accumulate until Pkg.gc() is called on Julia 1.6 (or later).

Cheers!

Elliot Saba (@staticfloat) and Fredrik Ekre (@fredrikekre)

28 Likes

What happens to a scratch space after Julia removes a package with Pkg.remove, but before Pkg.gc collects its garbage?

Nothing.

2 Likes