How to Clear DHT Cache in aria2?

This article provides a straightforward guide on how to clear the Distributed Hash Table (DHT) routing table cache in the aria2 download utility. When downloading torrents, aria2 saves DHT node data to a cache file to speed up future connections; however, a corrupted cache can cause connection issues or slow download speeds. By locating and removing this cache file (dht.dat or dht6.dat), or by using specific command-line flags, you can reset your DHT routing table and refresh your peer connections.

Locate and Delete the DHT Cache Files

The most direct way to clear the DHT cache is to manually delete the files where aria2 stores this session data. By default, aria2 saves these files in your current working directory or your user profile directory, depending on your operating system and configuration.

To clear the cache, close aria2 completely, search for these specific files on your system, and delete them. The next time you start aria2 with DHT enabled, it will bootstrap a brand-new routing table from scratch.

Disable the DHT File Saving via Command Line

If you want a temporary fix without permanently deleting your existing files, or if you want to prevent aria2 from loading the old cache during a specific session, you can use command-line options.

You can use the --dht-file-path option to point aria2 to a non-existent file or a temporary location, effectively forcing it to start fresh:

aria2c --dht-file-path=/dev/null [your-torrent-link]

(Note: On Windows, you would point this to an empty or temporary file path instead of /dev/null).

Prevent Future DHT Cache Retention

If you consistently experience issues with a stalled DHT routing table, you can disable the saving of the DHT file altogether by modifying your aria2 configuration file (aria2.conf).

Adding the following line prevents aria2 from saving the DHT routing table when it exits:

dht-file-path=

Leaving the path blank or disabling the save functionality ensures that every time you launch aria2, you start with a clean, real-time updated list of peers without relying on potentially stale cached data.