|
| 1 | +# CacheUp |
| 2 | + |
| 3 | +Simple CLI tool and go module for caching content on disk. |
| 4 | + |
| 5 | + |
| 6 | +## CLI Installation |
| 7 | +```bash |
| 8 | +go install github.com/zcag/cacheup@latest |
| 9 | +``` |
| 10 | +## Module Installation |
| 11 | +```bash |
| 12 | +go get github.com/zcag/cacheup@latest |
| 13 | +``` |
| 14 | + |
| 15 | +## Module Usage |
| 16 | + |
| 17 | +```go |
| 18 | +import ( "github.com/zcag/cacheup" ) |
| 19 | + |
| 20 | +func foo() { |
| 21 | + cacheup.Write("~/cache/file.json", "contents") |
| 22 | + cacheup.IsValid("~/cache/file.json", "30m") |
| 23 | + cacheup.Read("~/cache/file.json", "30m", "") |
| 24 | + cacheup.Read("~/cache/file.json", "30m", "curl http://example.com/fetch_fresh_file.json") |
| 25 | +} |
| 26 | + |
| 27 | +``` |
| 28 | + |
| 29 | + |
| 30 | +## CLI Usage |
| 31 | + |
| 32 | +```bash |
| 33 | +cacheup --help |
| 34 | + |
| 35 | +Usage: |
| 36 | + cacheup [command] |
| 37 | + |
| 38 | +Available Commands: |
| 39 | + completion Generate the autocompletion script for the specified shell |
| 40 | + help Help about any command |
| 41 | + read Read cached value |
| 42 | + valid Check if a cache file is valid |
| 43 | + write Write stdin to cache |
| 44 | + |
| 45 | +Flags: |
| 46 | + -t, --cache-max-age string max age of cache file (default: 1h), unit can be s/m/h/d for second/minute/hour/day (default "1h") |
| 47 | + -f, --cache-path string custom location for cache path for parent directory or file. directory paths should end with '/' |
| 48 | + (default: $XDG_CACHE_HOME/cacheup/<name>) |
| 49 | + -h, --help help for cacheup |
| 50 | + |
| 51 | +Use "cacheup [command] --help" for more information about a command. |
| 52 | +``` |
| 53 | +
|
| 54 | +### Example snippets |
| 55 | +
|
| 56 | +```bash |
| 57 | +cacheup read <name> |
| 58 | +cacheup read <name> -f ~/custom/cache/ |
| 59 | +cacheup read -f ~/custom/cache/file.json |
| 60 | + |
| 61 | +# Set command with -c to refresh if cache is invalid |
| 62 | +cacheup read <name> -c "curl XX" |
| 63 | +cacheup read <name> -t 30m -c "~/some/script.sh" |
| 64 | + |
| 65 | +./heavy_command.sh | cacheup write <name> |
| 66 | +curl http://example.com | cacheup -f ~/custom/cache/folder/ write <name> |
| 67 | +curl http://example.com | cacheup -f ~/custom/cache/file write |
| 68 | + |
| 69 | +cacheup valid <name> |
| 70 | +cacheup read <name> -f ~/custom/cache/ -t 30m |
| 71 | +cacheup read -f ~/custom/cache/file.json |
| 72 | +``` |
0 commit comments