Search code examples
orchardcms

What does the "check in memory" mean in Orchard CMS?


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.


Solution

  • 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.