Doctrine MongoDB 结果缓存 [英] Doctrine MongoDB result caching

查看:17
本文介绍了Doctrine MongoDB 结果缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何缓存 Doctrine MongoDB 结果?查看 Configuration 的代码,它似乎没有像标准 Doctrine 这样的内置结果缓存,只有一个查询缓存.

How would one go about caching Doctrine MongoDB results? Looking at the code for Configuration it doesn't appear to have a built in result cache like standard Doctrine, only a query cache.

我曾想过在应用程序中创建自己的缓存层,但返回的对象非常重,因为它们包含许多视图不需要的 Doctrine 逻辑.如何将对象配对,使它们实际上只是数据容器?

I have thought of creating my own cache layer in the app but the returned objects are quite heavy as they contain lots of Doctrine logic not needed by the view. How can I pair down the objects so they are effectively just data containers?

推荐答案

Doctrine MongoDB ODM 不支持查询缓存,所以这肯定是你暂时需要在你的应用程序中处理的事情.

Doctrine MongoDB ODM does not support query caching, so this is definitely something you'd need to handle in your application for the time being.

如果您对重物有疑问,很可能是代理实例(用于引用的文档),因为这些实例包含对内部 Doctrine 服务(例如 UnitOfWork)的引用.如果你想有效地缓存这些,你基本上需要在存储之前剔除这些引用,然后在从缓存中获取它们之后恢复它们.这可能比它的价值更麻烦,但它会将对象减少到您想要的数据容器.

If you have an issue with heavy objects, it's most likely the Proxy instances (for referenced documents), as those contain references to internal Doctrine services (e.g. UnitOfWork). If you wanted to cache these efficiently, you'd essentially need to cull those references before storage and then restore them after fetching from the cache. That's likely to be more trouble than its worth, but it would reduce the objects to the data containers that you want.

或者,如果您使用查询构建器,您可以禁用水合,然后为返回的数组结果实施缓存.除此之外,您还可以查看应用程序中的缓存视图(这在 Symfony2 中非常理想,一个请求可能会到达多个控制器,每个控制器都可以应用自己的缓存规则并选择性地使用 ESI).

Alternatively, if you're using the query builder, you could disable hydration and then implement caching for returned array results. Beyond that, you could look into caching views in your application (this is ideal in Symfony2, where one request might hit several controllers, each of which can apply their own caching rules and optionally utilize ESI).

这篇关于Doctrine MongoDB 结果缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆