项目作者: andornaut

项目描述 :
Run a command and cache its results
高级语言: Shell
项目地址: git://github.com/andornaut/cache-command.git
创建时间: 2018-08-11T19:11:59Z
项目社区:https://github.com/andornaut/cache-command

开源协议:MIT License

下载


cache-command

Run a command and cache its results.

Tested on Linux and macOS.

./cache-command [OPTIONS] -- COMMAND saves the stdout, stderr, and exit code of COMMAND in a cache and
returns the same on subsequent invocations.

  1. $ echo -e '#!/bin/bash\n echo stdout; sleep 5; echo stderr >&2; exit 1' > five-seconds
  2. $ chmod 755 five-seconds
  3. $ TIMEFORMAT=%R
  4. $ time ./five-seconds ; echo "Exit code: $?"
  5. stdout
  6. stderr
  7. 5.004
  8. Exit code: 1
  9. $ time ./cache-command -- ./five-seconds ; echo "Exit code: $?"
  10. stdout
  11. stderr
  12. 5.012
  13. Exit code: 1
  14. $ time ./cache-command -- ./five-seconds ; echo "Exit code: $?"
  15. stdout
  16. stderr
  17. 0.010
  18. Exit code: 1

Note that cache-command should not be used to run programs that output sensitive information.

Inspired by this StackOverflow answer.

Requirements

Installation

  1. make install

Usage

  1. $ ./cache-command -h
  2. Usage: cache-command [-b PATH] [-e SECONDS] [-h] [-p] [-r] [-v] -- COMMAND
Option Description
-b PATH Base directory for the cache (default: ${XDG_RUNTIME_DIR}/cache-command)
-e SECONDS Cache expiration in seconds
-h Print help text
-p Purge the cache for a particular command
-r Remove the base directory (and any caches that it contains)
-v Print verbose output to aid with debugging