Doctrine Common
  1. Doctrine Common
  2. DCOM-130

Paths in Doctrine\Common\Cache\FileCache could create large directory indexes

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.3
    • Fix Version/s: None
    • Component/s: Caching
    • Labels:
      None
    • Environment:
      Any

      Description

      The way paths are created within FileCache currently, there is a theoretical maximum of 16^12 directories in the cache directory, which is quite a large number. Usually schemes like this are used to restrict the number of files in one directory.

      Comparing with git, for example, the dirs are arranged

      00/
      1c/
      ...
      ff/

      and then the object store within those directories, which is a lot more manageable, say if you happen to type ls in the cache directory, you will get a maximum listing of 256 dirs. PhpThumb does something similar when caching images.

      How about something like this for getFilename():

      $idHash = md5($id);
      $path = substr($idHash, 0, 2) . DIRECTORY_SEPARATOR . substr($idHash, 2, 2) . DIRECTORY_SEPARATOR . substr($idHash, 4);
      $path = $this->directory . DIRECTORY_SEPARATOR . $path;

      return $path . $id . $this->extension;

      Not nearly so elegant, but I think this has better properties for the file system. Also I would be tempted to use one of the sha family hashes and not to include the $id within the filename, but perhaps this is helpful for debugging?

        Activity

        R Churchill created issue -

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            R Churchill
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: