Java cache file names

I was wondering how Java generates the file names for its temporary cache files and after googling around, I found the answer in the Java source code – the function responsible is called generateCacheFileName and its implementation has changed over the time; here is how they do it in JDK 5 and 6/7:

JDK 5.xx

Files are saved in the following location:

  • %USERPROFILE%\Application Data\Sun\Java\Deployment\
    cache\javapi\v1.0\[cachefilename]

The procedure for generating [cachefilename] is described here:

JDK 6.xx-7.xx

Files are saved in the following location:

  • %USERPROFILE%\Local Settings\Application Data\Sun\Java\Deployment\
    cache\6.0\[cachebucket]\[cachefilename]

The procedure for generating [cachebucket]\[cachefilename] is described here:

The code

I ripped the code from these sources and created a simple java snippet that helps to test cache file name for a given URL. At the moment it has a small bug, but I hope you won’t notice it 🙂

Example – JRE 1.5

I googled around and found an old applet that worked under JRE 1.5, then visited the page so that the cached files could be created; the URL passed to the cachename Java program produces exactly same result:

javacache_1

Example – JRE 1.6-1.7

I simply visited Oracle web page that detects the browser and let the applet load:

javacache_2
Download

You can download the code here.

To compile, run:

javac cachename.java

To execute, run:

java cachename url