“检查内存"有什么作用?在 Orchard CMS 中是什么意思? [英] What does the "check in memory" mean in Orchard CMS?

查看:61
本文介绍了“检查内存"有什么作用?在 Orchard CMS 中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试自定义由 Orchard.ContentManagement.DefaultContentManager 执行的查询,但是下面的代码 *1 使我的努力毫无用处:

I tried to customize the queries executed by Orchard.ContentManagement.DefaultContentManager but the following peace of code *1 render my efforts useless:

class DefaultContentManager 
{
  ...

  public virtual ContentItem Get(int id, VersionOptions options, QueryHints hints) {
        ...
        // implemention of the query comes here
        ...
  *1 -> // no record means content item is not in db
        if (versionRecord == null) {
            // check in memory
            var record = _contentItemRepository.Get(id);
            if (record == null) {
                return null;
            }

            versionRecord = GetVersionRecord(options, record);

            if (versionRecord == null) {
                return null;
            }
        }

查询被正确执行并且它不返回任何数据(这是我的目标)但之后第二次尝试 *1 被执行以仍然获取内容项.

The query is executed correctly and it does not return any data (which was my goal) but afterwards a second attempt *1 is executed to still get the content item.

为什么会有这部分代码?它的目的是什么?还有为什么评论状态check in memory然后查询repository(DB表).

Why is this part of code there? What is its purpose? Also why does the comment state check in memory and then the repository (DB table) is queried.

推荐答案

此时已经验证该项目不存在于数据库中,但它可能只是在同一请求期间通过代码创建的.在这种情况下,nHibernate 会话有该项目,但数据库还没有它.存储库直接访问会话,而不是直接访问数据库,所以如果它在那里,它会检索它,但这会发生在内存中.

It's already been verified at this point that the item doesn't exist in the database, but it may have just been created from code during the same request. In that case, the nHibernate session has the item, but the database doesn't have it yet. The repository hits the session, not the db directly, so if it's there, it'll retrieve it, but that'll happen in memory.

这篇关于“检查内存"有什么作用?在 Orchard CMS 中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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