{"id":1847,"date":"2013-04-19T18:44:52","date_gmt":"2013-04-19T18:44:52","guid":{"rendered":"http:\/\/www.hexacorn.com\/blog\/?p=1847"},"modified":"2013-04-19T18:49:25","modified_gmt":"2013-04-19T18:49:25","slug":"java-cache-file-names","status":"publish","type":"post","link":"https:\/\/www.hexacorn.com\/blog\/2013\/04\/19\/java-cache-file-names\/","title":{"rendered":"Java cache file names"},"content":{"rendered":"<p>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 &#8211; the function responsible is called <em>generateCacheFileName<\/em> and its implementation has changed over the time; here is how they do it in JDK 5 and 6\/7:<\/p>\n<p><strong>JDK 5.xx<\/strong><\/p>\n<p>Files are saved in the following location:<\/p>\n<ul>\n<li>\n<pre>%USERPROFILE%\\Application Data\\Sun\\Java\\Deployment\\\r\ncache\\javapi\\v1.0\\[cachefilename]<\/pre>\n<\/li>\n<\/ul>\n<p>The procedure for generating [cachefilename] is described here:<\/p>\n<ul>\n<li><a href=\"http:\/\/javasourcecode.org\/html\/open-source\/jdk\/jdk-5.0\/sun\/plugin\/cache\/Cache.java.html#line.249\">http:\/\/javasourcecode.org\/html\/open-source\/jdk\/jdk-5.0\/sun\/plugin\/cache\/Cache.java.html#line.249<\/a><\/li>\n<\/ul>\n<p><strong>JDK 6.xx-7.xx<\/strong><\/p>\n<p>Files are saved in the following location:<\/p>\n<ul>\n<li>\n<pre>%USERPROFILE%\\Local Settings\\Application Data\\Sun\\Java\\Deployment\\\r\ncache\\6.0\\[cachebucket]\\[cachefilename]<\/pre>\n<\/li>\n<\/ul>\n<p>The procedure for generating [cachebucket]\\[cachefilename] is described here:<\/p>\n<ul>\n<li><a href=\"http:\/\/javasourcecode.org\/html\/open-source\/jdk\/jdk-6u23\/com\/sun\/deploy\/cache\/Cache.java.html#line.2013\">http:\/\/javasourcecode.org\/html\/open-source\/jdk\/jdk-6u23\/com\/sun\/deploy\/cache\/Cache.java.html#line.2013<\/a><\/li>\n<\/ul>\n<p><strong>The code<\/strong><\/p>\n<p>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&#8217;t notice it \ud83d\ude42<\/p>\n<p><strong>Example &#8211; JRE 1.5<\/strong><\/p>\n<p>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:<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2013\/04\/javacache_1.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-1850\" alt=\"javacache_1\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2013\/04\/javacache_1.jpg\" width=\"615\" height=\"132\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2013\/04\/javacache_1.jpg 851w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2013\/04\/javacache_1-300x64.jpg 300w\" sizes=\"(max-width: 615px) 100vw, 615px\" \/><\/a><\/p>\n<p><strong>Example &#8211; JRE 1.6-1.7<\/strong><\/p>\n<p>I simply visited Oracle web page that detects the browser and let the applet load:<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2013\/04\/javacache_2.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-1851\" alt=\"javacache_2\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2013\/04\/javacache_2.jpg\" width=\"620\" height=\"156\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2013\/04\/javacache_2.jpg 746w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2013\/04\/javacache_2-300x75.jpg 300w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/a><br \/>\n<strong>Download<\/strong><\/p>\n<p>You can download the code <a href=\"https:\/\/www.hexacorn.com\/tools\/cachename.java\">here<\/a>.<\/p>\n<p>To compile, run:<\/p>\n<pre style=\"padding-left: 30px;\">javac cachename.java<\/pre>\n<p>To execute, run:<\/p>\n<pre style=\"padding-left: 30px;\">java cachename url<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8211; the function responsible is called generateCacheFileName and its implementation has changed over &hellip; <a href=\"https:\/\/www.hexacorn.com\/blog\/2013\/04\/19\/java-cache-file-names\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[19,5],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/1847"}],"collection":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/comments?post=1847"}],"version-history":[{"count":8,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/1847\/revisions"}],"predecessor-version":[{"id":1857,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/1847\/revisions\/1857"}],"wp:attachment":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/media?parent=1847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/categories?post=1847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/tags?post=1847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}