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

**URL:** <https://discourse.julialang.org/t/ann-scratch-jl-package-specific-mutable-data-containers/45855>\
**Category:** Package Announcements\
**Created:** [August 31, 2020, 6:26pm UTC](https://discourse.julialang.org/t/ann-scratch-jl-package-specific-mutable-data-containers/45855 "2020-08-31T18:26:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [August 31, 2020, 6:26pm UTC](https://discourse.julialang.org/t/ann-scratch-jl-package-specific-mutable-data-containers/45855/1 "2020-08-31T18:26:21Z")

</div>

## Scratch.jl

[_Scratch.jl_](https://github.com/JuliaPackaging/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-auto
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](https://github.com/JuliaPackaging/Scratch.jl/blob/master/README.md) file for more details and more examples, and please [open an issue ticket](https://github.com/JuliaPackaging/Scratch.jl/issues/new) 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)

---

<div class="post-metadata">

**Author:** ![derekmahar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/derekmahar/32/216439_2.png) [@derekmahar](https://discourse.julialang.org/u/derekmahar)\
**Post date:** [September 1, 2020, 5:00pm UTC](https://discourse.julialang.org/t/ann-scratch-jl-package-specific-mutable-data-containers/45855/3 "2020-09-01T17:00:48Z")

</div>

> [@fredrikekre](#):
>
> 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.

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

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [September 1, 2020, 5:14pm UTC](https://discourse.julialang.org/t/ann-scratch-jl-package-specific-mutable-data-containers/45855/4 "2020-09-01T17:14:40Z")

</div>

Nothing.
