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

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

问题描述

如何缓存Doctrine MongoDB结果?查看配置代码,它似乎没有像标准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.

如果您遇到重物问题,则很可能是Proxy实例(用于引用的文档),因为这些实例包含对内部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).

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

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