2017-03-13 16:16
浏览 220

可以在Redis中存储渲染的html吗? [关闭]

I'm using Symfony framework with Redis as cache. My controller fetches info from third-party API, creates php objects and places them to a Twig template. Is it good decision to cache rendered HTML in Redis? Maybe better to serialize objects and save them? In last case server will spend time to unserializing and templating but I feel there is something not-so-pretty in first case.

Thank you.

图片转代码服务由CSDN问答提供 功能建议

我正在使用Symfony框架和Redis作为缓存。 我的控制器从第三方API获取信息,创建php对象并将它们放到Twig模板中。 在Redis中缓存渲染的HTML是否是一个好的决定? 也许更好的序列化对象并保存它们? 在最后一种情况下,服务器将花费时间来反序列化和模板化,但我觉得在第一种情况下有一些不那么漂亮的东西。


  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsdzvprlp51692469 2017-03-13 18:02

    For that use a reverse proxy cache like Varnish that is designed for this kind of purposes. It has powerful methods for cache invalidation that are the main cause of headaches when dealing with caches.

    If you use redis each request still impacts your application causing the whole DI container to be loaded, until your events (or whatever method you use) process the request, checks if it is in redis and if it's still valid and deliver it.

    With a reverse proxy cache if your app only is impacted when fresh content is needed.

    As has been said in comments a system like redis can be some kind of "intermediate" cache in which you can store Api results or internal heavy and not so "changing" calculations to improve the overall performance.

    打赏 评论

相关推荐 更多相似问题