4

I'm using SitecoreContext.Cast(item, true, true) to map an item. It looks like elsewhere in the code, the same item has been casted to BaseType WITHOUT inferType = true before I make that call. When I do the next call with inferType = true, I'm getting the item back as a BaseType, instead of the inferred type. It appears that the item is being placed in the cache as BaseType, and the inferType = true call gets the item from the cache without inferring the type.

Is there something missing here, or a way to tell the Glass cache that it needs to pull the correct type out of the cache?

1

Could you try overriding the CacheKeyGenerator with the following class:

public class CacheKeyGenerator : ICacheKeyGenerator
{
    public string Generate(ObjectConstructionArgs args)
    {
        var context = args.AbstractTypeCreationContext as SitecoreTypeCreationContext;

        return string.Format("{0}{1}{2}{3}{4}{5}{6}{7}",
            context.SitecoreService.GlassContext.Name,
            Sitecore.Context.Site == null ? string.Empty : Sitecore.Context.Site.Name,
            context.Item.ID,
            context.Item["__Revision"],
            context.Item.Language.Name,
            context.Item.Database.Name,
            args.Configuration.Type.FullName,
            context.IsLazy
            );
    }
}

Let me know if this fixes the issue because I think this is a bug.

  • I had found a temporary work around and wasn't able to get back to this issue until yesterday. I tested it and this did indeed fix the issue. Thanks! – Drew Dec 12 '17 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.