You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23-1Lines changed: 23 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -851,6 +851,29 @@ You can combine the options of the Mbed update command for the following scenari
851
851
852
852
Use these with caution because your uncommitted changes and unpublished libraries cannot be restored.
853
853
854
+
## Repository caching
855
+
856
+
To minimize traffic and reduce import times, by default Mbed CLI caches repositories by storing their indexes under the Mbed CLI user config folder - typically `~/.mbed/mbed-cache/` on UNIX systems, or `%userprofile%/.mbed/mbed-cache/` on Windows systems. Compared to a fully checked out repository, indexes are significantly smaller in size and number of files and contain the whole revision history of that repository. This allows Mbed CLI to quickly create copies of previously downloaded repository indexes and pull/fetch only the latest changes from the remote repositories, therefore dramatically reducing network traffic and download times, especially for big repositories such as `mbed-os`.
857
+
858
+
You can manage the Mbed CLI caching behavior with the following subcommands:
859
+
860
+
```
861
+
mbed cache [on|off|dir <path>|ls|purge|-h|--help]
862
+
```
863
+
864
+
*`on` - Turn repository caching on. This uses either the user specified cache directory or the default one. See "dir".
865
+
*`off` - Turn repository caching off. Note that this doesn't purge cached repositories. See "purge".
866
+
*`dir` - Set cache directory. Set to "default" to let Mbed CLI determine the cache directory location. Typically, this is `~/.mbed/mbed-cache/` on UNIX systems, or `%%userprofile%%/.mbed/mbed-cache/` on Windows systems.
867
+
*`ls` - List cached repositories and their size.
868
+
*`purge` - Purge cached repositories. Note that this doesn't turn caching off.
869
+
*`-h` or `--help` - Print cache command options.
870
+
871
+
If no subcommand is specified to `mbed cache`, Mbed CLI prints the current cache setting (ENABLED or DISABLED) and the path to the local cache directory.
872
+
873
+
For safety reasons, Mbed CLI uses the `mbed-cache` subfolder to a user specified location. This ensures that no user files are deleted during `purge` even if the user has specified root/system folder as a cache location (for example, `mbed cache dir /` or `mbed cache dir C:\`).
874
+
875
+
**Security notice**: If you use cache location outside your user home/profile directory, then other system users might be able to access the repository cache and therefore the data of the cached repositories.
876
+
854
877
## Mbed CLI configuration
855
878
856
879
You can streamline many options in Mbed CLI with global and local configuration.
@@ -874,7 +897,6 @@ Here is a list of configuration settings and their defaults:
874
897
*`ARM_PATH`, `ARMC6_PATH`, `GCC_ARM_PATH`, `IAR_PATH` - defines the path to Arm Compiler 5 and 6, GCC Arm and IAR Workbench toolchains. Default: none.
875
898
*`protocol` - defines the default protocol used for importing or cloning of programs and libraries. The possible values are `https`, `http` and `ssh`. Use `ssh` if you have generated and registered SSH keys (Public Key Authentication) with a service such as GitHub, GitLab, Bitbucket and so on. Read more about SSH keys [here](https://help.github.com/articles/generating-an-ssh-key/). Default: `https`.
876
899
*`depth` - defines the *clone* depth for importing or cloning and applies only to *Git* repositories. Note that though this option may improve cloning speed, it may also prevent you from correctly checking out a dependency tree when the reference revision hash is older than the clone depth. Read more about shallow clones [here](https://git-scm.com/docs/git-clone). Default: none.
877
-
*`cache` - defines the local path that stores small copies of the imported or cloned repositories, and Mbed CLI uses it to minimize traffic and speed up future imports of the same repositories. Use `on` or `enabled` to turn on caching in the system temp path. Use `none` to turn caching off. Default: none (disabled).
dict(name='on', nargs='?', help='Turn repository caching on. Will use either the default or the user specified cache directory.'),
2786
+
dict(name='off', nargs='?', help='Turn repository caching off. Note that this doesn\'t purge cached repositories. See "purge".'),
2787
+
dict(name='dir', nargs='?', help='Set cache directory. Set to "default" to let mbed CLI determine the cache directory location (%s/mbed-cache/).'%Global().path),
2788
+
dict(name='ls', nargs='?', help='List cached repositories and their sizes.'),
2789
+
dict(name='purge', nargs='?', help='Purge cached repositories. Note that this doesn\'t turn caching off'),
2790
+
help='Repository cache management\n\n',
2791
+
description=(
2792
+
"Repository cache management\n"
2793
+
"To minimize traffic and reduce import times, Mbed CLI can cache repositories by storing their indexes.\n"
2794
+
"By default repository caching is turned on. Turn it off if you experience any problems.\n"))
action("Repository cache is now %s."%str(cfg['cache']).upper())
2805
+
action("Cache location \"%s\""%cfg['cache_dir'])
2806
+
elifcmd=='dir':
2807
+
ifnotargument:
2808
+
error("Please specify directory or path to cache repositories. Alternatively specify \"default\" to cache repositories in the default user home location.")
2809
+
ifnotos.path.exists(argument):
2810
+
try:
2811
+
os.makedirs(argument)
2812
+
except (IOError, ImportError, OSError):
2813
+
error("Unable to create cache directory \"%s\""%argument, 128)
2814
+
elifnotos.path.isdir(argument):
2815
+
error("The specified location \"%s\" is not a directory"%argument, 128)
2816
+
eliflen(os.listdir(argument)) >1:
2817
+
warning("Directory \"%s\" is not empty."%argument)
2818
+
g.set_cfg('CACHE_DIR', argument)
2819
+
action('Repository cache location set to \"%s\"'%argument)
2820
+
elifcmd=='ls':
2821
+
defget_size_(path):
2822
+
size=0
2823
+
fordirpath, dirs, filesinos.walk(path):
2824
+
forfinfiles:
2825
+
size+=os.path.getsize(os.path.join(dirpath, f))
2826
+
returnsize
2827
+
action("Listing cached repositories in \"%s\""%cfg['cache_base'])
0 commit comments