title: Cache directory structure
body: <p>I'm in the process of implementing caching for my project. After looking at cache directory structures, I've seen many examples like:</p>
  
  <pre><code>cache
  cache/a
  cache/a/a/
  cache/a/...
  cache/a/z
  cache/...
  cache/z
  ...
  </code></pre>
  
  <p>You get the idea. Another example for storing files, let's say our file is named <code>IMG_PARTY.JPG</code>, a common way is to put it in a directory named:</p>
  
  <pre><code>files/i/m/IMG_PARTY.JPG
  </code></pre>
  
  <p>Some thoughts come to mind, but I'd like to know the real reasons for this.</p>
  
  <ul>
  <li><p>Filesystems doing linear lookups find files faster when there's fewer of them in a directory. Such structure spreads files thin.</p></li>
  <li><p>To not mess up *nix utilities like <code>rm</code>, which take a finite number of arguments and deleting large number of files at once tends to be hacky (having to pass it though <code>find</code> etc.)</p></li>
  </ul>
  
  <p>What's the real reason? What is a "good" cache directory structure and why?</p>