Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the symfony cache file system handle ext2 32000 files in the same directory limitation?

Does the symfony cache system handle ext2 32000 files in the same directory limitation ?

I have 80000 users and i want to cache their profiles but do symfony cache system handle the ext2 limitation ?

i'm also posting for the others who will face the same problem.

like image 276
belaz Avatar asked Nov 15 '22 11:11

belaz


1 Answers

I'm not 100% sure whether my answer is correct but in PROJECT/lib/symfony/cache/sfCacheFile.class.php there is a method: sfCacheFile::getFilePath() that returns a path to a file. It seems that there is no any protection against limitations of ext2 filesystem.

But there is a very simple solution - override that class:

  1. In PROJECT/apps/APP/config/factories.yml set your own cache class:

    default:
    # Others factories (if any)
    
      view_cache:
        class: myOwnFileCache
        param:
          automatic_cleaning_factor: 0
          cache_dir:                 %SF_TEMPLATE_CACHE_DIR%
          lifetime:                  86400
          prefix:                    %SF_APP_DIR%/template
    
  2. Now create that class and make sure it extends sfFileCache and overrides getFilePath()

    # PROJECT/lib/PROJECT/cache/myOwnFileCache.class.php        
    class myOwnFileCache extends sfFileCache {
        protected getFilePath($key) {
            /*
                Convert from: abcdef
                          to: a/b/abcdef
            */
            $key = substr($key, 0, 1) . DIRECTORY_SEPARATOR . substr($key, 1, 1) . DIRECTORY_SEPARATOR . $key;
            return parent::getFilePath($key);
        }
    

    }

  3. Clear cache: ./symfony cc

Now you need 32000 cache keys that starts with the exact same two letters/digits to crush your filesystem.

like image 81
Crozin Avatar answered Dec 09 '22 18:12

Crozin