Cheat Sheet Clear Cache

Cheat Sheet Clear Cache

Zakiego

Zakiego

@zakiego

Read in Bahasa Indonesia 🇮🇩

Background

I am very fond of clearing caches. There’s something satisfying about freeing up space and ensuring that my development environment is as clean and efficient as possible. Over time, I've gathered a collection of commands and tools that make it easy to manage and clear caches for various package managers and development tools. Here's a handy cheat sheet for anyone who shares my enthusiasm for a clutter-free system.

Notes

Please note, you should check each command before running it and proceed at your own risk. Clearing caches can sometimes lead to unexpected issues or the need to re-download packages and rebuild projects.

Despite these potential drawbacks, keeping caches clean helps maintain an efficient and organized workspace, ensuring that old or corrupted files don’t interfere with development.

Cheat sheet

PNPM

pnpm store prune

Ref: https://github.com/orgs/pnpm/discussions/4413


NPM

npm cache clean --force

Ref: https://www.warp.dev/terminus/clear-npm-cache


Yarn

yarn cache clean

Ref: https://yarnpkg.com/cli/cache/clean


Bun

bun pm cache rm

Ref: https://bun.sh/docs/cli/pm


Node Modules

This tool allows you to list any node_modules directories in your system, as well as the space they take up. You can then select which ones you want to erase to free up space. Yay!

npkill

Ref: https://www.npmjs.com/package/npkill


Docker

Everything

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]

Container

docker container prune

# WARNING! This will remove all stopped containers.
# Are you sure you want to continue? [y/N]

Image

docker image prune -a

# WARNING! This will remove all dangling images.
# Are you sure you want to continue? [y/N]

The -a flag removes all unused images, not just the dangling ones.

Volume

docker volume prune

# WARNING! This will remove anonymous local volumes not used by at least one container.
# Are you sure you want to continue? [y/N]

Build Cache

docker buildx prune

# WARNING! This will remove all dangling build cache.
# Are you sure you want to continue? [y/N]

Network

docker network prune

# WARNING! This will remove all custom networks not used by at least one container.
# Are you sure you want to continue? [y/N]

Ref:


NVM (Node Version Manager)

nvm cache clear

Ref: https://github.com/nvm-sh/nvm?tab=readme-ov-file


Next.js

Delete .next folder

This command is generated by ChatGPT. Do with your own risk!

find . -type d -name ".next" -exec rm -rf {} +

Biome.js

Delete this folder:

  • Linux: ~/.cache/biome;
  • Windows: C:\Users\<UserName>\AppData\Local\biomejs\biome\cache
  • macOS: /Users/<UserName>/Library/Caches/dev.biomejs.biome

Ref: https://biomejs.dev/guides/integrate-in-editor/#daemon-logs