What does the “check in memory” mean in Orchard CMS?

て烟熏妆下的殇ゞ 提交于 2019-12-10 20:09:27

问题


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;
            }
        }

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.

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.


回答1:


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.



来源:https://stackoverflow.com/questions/37841249/what-does-the-check-in-memory-mean-in-orchard-cms

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!