キャッシュクリア方法


概要

各種パッケージマネージャのキャッシュクリアコマンドをまとめる。

Git

git gc --aggressive --prune=now

Docker

DockerはDockerイメージ、コンテナ、ボリューム、ネットワークのそれぞれでキャッシュが生成される。

各キャッシュをまとめて削除するsystem pruneサブコマンドと、各キャッシュを個別に削除するXXXX pruneサブコマンドの2種類のキャッシュクリアのコマンドが用意されている。

全部削除

$ docker system prune
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
  - all dangling build cache

Are you sure you want to continue? [y/N] 

なお、-aオプションを付けると未使用イメージと全てのビルドキャッシュも削除される。

$ docker system prune -a
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all images without at least one container associated to them
  - all build cache

Are you sure you want to continue? [y/N] 

コンテナのみ削除

docker container prune

イメージのみ削除

danglingイメージ(タグ付けされていないイメージ)削除

docker image prune

未使用イメージ削除

docker image prune -a

未使用ネットワークのみ削除

docker network prune

未使用ボリュームのみ削除

docker volume prune

Linux

apt

apt-get clean

yum

yum clean all

JavaScript

bower

bower cache clean

npm

npm cache clean

yarn

yarn cache clean

Java

maven

mavenはキャッシュクリア用のコマンドがない。ディレクトリを丸ごと削除する。

rm -rf ~/.m2/repository/

Python

pip

pipはキャッシュクリア用のコマンドがない。ディレクトリを丸ごと削除する。

rm -rf XXX

XXXはOSに依存するディレクトリ。OS別のディレクトリは以下の通り。

  • Unix ~/.cache/pip
  • macOS ~/Library/Caches/pip
  • Windows <CSIDL_LOCAL_APPDATA>\pip\Cache

出典:https://stackoverflow.com/questions/34578168/where-is-pip-cache-folder