question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with `SitecoreParentMapper` and caching

See original GitHub issue

Hi,

I have a problem with Glass mapper caching. I try to describe the issue as good as possible. Given is the following base model:

public interface IBaseItem
{
    ...

    [SitecoreParent(IsLazy = true, InferType = true)]
    IBaseItem Parent { get; set; }

    ...
}

Where there are several content types which can be loaded into Parent (due to infertype). All of them have [SitecoreType(Cachable = true)]. To build my 3-level main navigation, I call the following code for each item:

protected bool IsAncestorOfItem(IBaseItem potentialAncestor, IBaseItem item)
{
    while (item != null)
    {
        if (item.ItemId == potentialAncestor.ItemId)
        {
            return true;
        }

        item = item.Parent;
    }

    return false;
}

With enabled Glass cache (new SitecoreContext { CacheEnabled = true };) this results in the following error:

Exception: System.NullReferenceException
Message: Object reference not set to an instance of an object.
Source: Glass.Mapper
   at Glass.Mapper.AbstractService.RunConfigurationPipeline(AbstractTypeCreationContext abstractTypeCreationContext)
   at Glass.Mapper.AbstractService.InstantiateObject(AbstractTypeCreationContext abstractTypeCreationContext)
   at Glass.Mapper.Sc.SitecoreService.CreateType(Type type, Item item, Boolean isLazy, Boolean inferType, Dictionary`2 parameters, Object[] constructorParameters)
   at Glass.Mapper.Sc.DataMappers.SitecoreParentMapper.MapToProperty(AbstractDataMappingContext mappingContext)
   at Glass.Mapper.Pipelines.ObjectConstruction.Tasks.CreateInterface.InterfacePropertyInterceptor.LoadValue(AbstractPropertyConfiguration propertyConfiguration)
   at Glass.Mapper.Pipelines.ObjectConstruction.Tasks.CreateInterface.InterfacePropertyInterceptor.Intercept(IInvocation invocation)
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Castle.Proxies.IOverviewPageProxy.get_Parent()
   at Feature.Navigation.Services.MainNavigationService.IsAncestorOfItem(IBaseItem potentialAncestor, IBaseItem item)
   .........

The error won’t be thrown for all items. Usually the first item called after an app pool recycle works, all other calls doesn’t work. If I disable Glass cache (new SitecoreContext { CacheEnabled = false };) I have no issues at all.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
mikeedwards83commented, Nov 21, 2016

Hi @rootix I am working on an implementation at the moment that means if the requested model is set to be cachable then lazy loading is disabled. This will remove the need to mark every property as lazy=false and I hope resolve the issue you have described.

1reaction
kevinbrechbuehlcommented, Oct 4, 2016

Ehm no 😉 I just completely the property, didn’t see that true is the default value. And yes, of course both of you are right, when setting this explicitely to false then it works perfectly.

So the key message here is: Do not use lazy loading in properties when using Glass cache. Is there a way to globally disable lazy loading (also if this was set on a property)? Could this be disabled somewhere within the SitecoreService if cache is enabled?

Thanks for helping me out!

Read more comments on GitHub >

github_iconTop Results From Across the Web

SharePoint Caching Problems with Lists
I have been having odd behaviors with regard to configuring SharePoint lists that started occurring the last 2 days: (1) When adding list...
Read more >
Caching challenges and strategies
An external cache stores cached data in a separate fleet, for example using Memcached or Redis. Cache coherence issues are reduced because the...
Read more >
Homepage Issues with cache
Hello, I have started using your caching softwware after many years with wp rocket (this is now fully removed, all folders and database)...
Read more >
Caching in GitLab CI/CD
A cache is one or more files a job downloads and saves. Subsequent jobs that use the same cache don't have to download...
Read more >
Specifying data elements for local data caching
Procedure · In the Configure data caching pane, click the Action icon Action icon , and then click Enable all or Disable all....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found