symfony 缓存文件系统是否可以处理同一目录限制中的 ext2 32000 个文件?

发布于 2024-08-30 07:53:27 字数 138 浏览 3 评论 0 原文

symfony 缓存系统是否可以处理同一目录限制中的 ext2 32000 个文件?

我有 80000 个用户,我想缓存他们的配置文件,但是 symfony 缓存系统可以处理 ext2 限制吗?

我还为其他将面临同样问题的人发帖。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我是男神闪亮亮 2024-09-06 07:53:27

我不确定我的答案是否正确,但在 PROJECT/lib/symfony/cache/sfCacheFile.class.php 中有一个方法: sfCacheFile::getFilePath() 返回文件的路径。似乎没有任何针对 ext2 文件系统限制的保护措施。

但有一个非常简单的解决方案 - 覆盖该类:

  1. PROJECT/apps/APP/config/factories.yml 设置您自己的缓存类:

    <前><代码>默认:
    # 其他工厂(如果有)

    视图缓存:
    类: myOwnFileCache
    参数:
    自动清洁系数:0
    缓存目录:%SF_TEMPLATE_CACHE_DIR%
    寿命:86400
    前缀:%SF_APP_DIR%/模板

  2. 现在创建该类并确保它扩展sfFileCache< /code> 并覆盖 getFilePath()

    # PROJECT/lib/PROJECT/cache/myOwnFileCache.class.php        
    类 myOwnFileCache 扩展 sfFileCache {
        受保护的 getFilePath($key) {
            /*
                转换自:abcdef
                          至:a/b/abcdef
            */
            $key = substr($key, 0, 1) 。 DIRECTORY_SEPARATOR 。 substr($key, 1, 1) 。 DIRECTORY_SEPARATOR 。 $键;
            返回父级::getFilePath($key);
        }
    

    }

  3. 清除缓存:./symfony cc

现在您需要 32000 个以完全相同两个字母/数字开头的缓存键来粉碎您的文件系统。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文