cmdcache(1)
| CMDCACHE(1) | User Contributed Perl Documentation | CMDCACHE(1) |
NAME
cmdcache - simple cache for command output
SYNOPSIS
cmdcache [-h] command FILE
DESCRIPTION
cmdcache wraps command and caches its output. command must take exactly one argument, an existent FILE (or possibly a directory). Previous command output is reused when "st_ino", "st_size", and "st_mtime" of the FILE match.
cmdcache can be sourced by specifying null argument for the command. Shell function with the same name is provided, and command can be a shell function, too. Suggested usage is as follows:
# implement custom command with a shell function
my_command() { local f="$1"; study "$f"; }
# grab cmdcache shell function
. cmdcache ""
# process arguments and cache the results
for f; do cmdcache my_command "$f"; done
Upon successful command completion, cache file is stored under "$HOME/.cmdcache/command" directory. The directory has up to 97 subdirectories, due to "mod 97" hash function. That is, the designed cache cacpacity is about 10k (100 files * 100 subdirs), and the capacity does not impose any performance hit.
When command return code is non-zero, cache file is not created, and the return code of cmdcache is that of the command. The return code is 2 if an error occurred (e.g. if FILE does not exist).
If FILE has changed upon command completion, the return code is 2. This means that FILE must not be modified by the command.
AUTHOR
Written by Alexey Tourbin <at@altlinux.org>.
COPYING
Copyright (c) 2005 Alexey Tourbin, ALT Linux Team.
This is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
SEE ALSO
| 2023-11-23 | perl v5.34.1 |
