Caching is a core concept in
import. Scripts are downloaded exactly once, and
then cached on your filesystem forever (unless the
variable is set).
Run this code
#!/usr/bin/env import # Import script files to the `/tmp` directory IMPORT_CACHE="/tmp" # Log information related to `import` to stderr IMPORT_DEBUG=1 # Force a fresh download of script files (like Shift + Reload in the browser) IMPORT_RELOAD=1 import assert
If you run this example, then you can see the file structure and order of operations because of the debug logging:
import: importing 'assert' import: normalized URL 'https://import.pw/assert' import: HTTP GET https://import.pw/assert import: resolved location 'https://import.pw/assert' -> 'https://raw.githubusercontent.com/importpw/assert/master/assert.sh' import: calculated hash 'https://import.pw/assert' -> '0a1c5188c768b3b150f1a8a104bb71a3fa160aad' import: creating symlink ‘/tmp/links/https/import.pw/assert’ -> ‘../../../data/0a1c5188c768b3b150f1a8a104bb71a3fa160aad’ import: successfully downloaded 'https://import.pw/assert' -> '/tmp/data/0a1c5188c768b3b150f1a8a104bb71a3fa160aad' import: sourcing '/tmp/links/https/import.pw/assert'
Now let's take a look at what the actual directory structure looks like:
$ tree /tmp /tmp ├── data │ └── bf671d3752778f91ad0884ff81b3e963af9e4a4f ├── links │ └── https │ └── import.pw │ └── assert -> ../../../data/bf671d3752778f91ad0884ff81b3e963af9e4a4f └── locations └── https └── import.pw └── assert
import generates three subdirectories under the
data- The raw shell scripts, named after the sha1sum of the file contents
links- Symbolic links that are named according to the import URL
locations- Files named according to the import URL that point to the real URL
IMPORT_CACHE environment variable is not set, the cache location
defaults to the directory
import.pw in the OS-specific user cache directory.
For this user cache directory
import considers (in order):
$XDG_CACHE_HOME(usually set on Linux)
$LOCALAPPDATA(usually set on Windows)
$HOME/Library/Cacheson macOS and