Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cossio/localstore.jl
Local storage of objects.
https://github.com/cossio/localstore.jl
Last synced: 10 days ago
JSON representation
Local storage of objects.
- Host: GitHub
- URL: https://github.com/cossio/localstore.jl
- Owner: cossio
- License: mit
- Created: 2020-04-12T15:02:44.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-08-09T22:29:10.000Z (about 1 year ago)
- Last Synced: 2024-10-09T06:55:28.721Z (28 days ago)
- Language: Julia
- Size: 120 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# LocalStore Julia package
This package provides a simple interface for storing and retrieving Julia objects locally.
Example:
```julia
using LocalStore# Define an item type. This should contain enough information
# to be able to reconstruct the desired object.
struct A
x::Int
end# Since store location is based on hash, it is recommended to
# define a hash function for custom types.
Base.hash(a::A, h::UInt) = hash(:A, hash(a.x, h))# Define how the item is stored on disk. The `path` is a dir, handled
# automatically by the LocalStore package.
LocalStore.save(a::A, path::String) = open("$path/file.txt", "w") do f
# some difficult computation you only want to do once
x2 = a.x^2
# maybe download some remote files# now save to disk the results
write(f, string(x2))
end# Define how the item is read from disk.
LocalStore.load(a::A, path::String) = open("$path/file.txt", "r") do f
parse(Int, readline(f))
end# Automatically checks if the requested object is stored. If not,
# it creates a local directory and saves it there and loads it.
# Next time `load` is called, the stored object is returned.
a = LocalStore.load(A(5))
```