Symfony 使用 Redis 作为默认缓存编译容器

und*_*Pez 5 php caching redis symfony

我有一个 Symfony 应用程序,我想使用 Redis 作为缓存系统。Symfony 开箱即用的默认缓存系统是文件系统缓存。

从文档中我了解到 Symfony 中有两个命名缓存;cache.app因此cache.system我使用以下 cache.yaml 将两者设置为 Redis:

framework:
    cache:
    # Put the unique name of your app here: the prefix seed
    # is used to compute stable namespaces for cache keys.
    prefix_seed: myteam/myapp

    default_redis_provider: "redis://redis:6379"

    # The app cache caches to the filesystem by default.
    # Other options include:

    # cache.app via Redis
    app: cache.adapter.redis

    # cache.system also
    system: cache.adapter.redis
Run Code Online (Sandbox Code Playgroud)

完成此操作后,我加载了一个示例页面并监视了缓存文件夹。我发现尽管在 Redis 中创建了密钥,但仍在缓存文件夹中创建文件。

我知道 Symfony 不建议弄乱内核在文件缓存中创建的文件,但即使是 cache/prod/Containerxxxxx 文件夹也会被写入。

不属于应用程序或系统的文件夹中可能会缓存什么?是否有另一个我错过的命名缓存?

yiv*_*ivi 11

此处的文件cache/prod/Containerxxxxx是编译后的容器文件。

它们始终写入您的文件系统,并且永远不会写入其他辅助缓存系统。

如果不从容器获取这些信息,Symfony 首先就不知道如何访问 Redis,容器在编译和构建时总是缓存到文件系统中。

  • cache.system用于注释、序列化器和验证等;但不适用于已编译的容器本身。

  • cache.appCacheInterface是应用程序缓存,如果您键入提示或Psr\\Cache\\CacheItemPoolInterface在服务方法中,则可以在应用程序中使用它。

总而言之,没有其他可以配置的缓存,因此 Symfony 会将编译后的容器存储在那里。这些文件是代码,存储在文件系统上。