Issue with `SitecoreParentMapper` and caching
See original GitHub issueHi,
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:
- Created 7 years ago
- Comments:8 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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 tofalse
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!