Skip to main content
6 of 7
Retagged
Gatogordo
  • 20.3k
  • 2
  • 39
  • 100

Sitecore.Caching.CustomCache changes with 8.2

I'm upgrading my site from Sitecore 8.1 to Sitecore 8.2, and one of the compile errors that I'm getting is

CS1503 Argument 3: cannot convert from 'long' to 'System.EventHandler<Sitecore.Caching.Generics.EntryRemovedEventArgs'

As I'm looking into this, I think that I remember reading that Sitecore completely changed how the cache is working in 8.2, and therefore I will need to change my code as well. Can someone provide an overview of what kind of changes I'll need to make to my code so that I can run on 8.2?

Edit

This class is based on the Sitecore.Cachine.CustomCache class. Here's the code that I'm having problems with:

    public void SetObject(string key, object content)
    {
        base.SetObject(key, content, EstimateObjectSize(content));
    }

    private long EstimateObjectSize(object obj)
    {
        long size = 0;
        try
        {
            using (Stream s = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(s, obj);
                size = s.Length;
            }
        }
        catch(SerializationException)
        {
            // object cannot be serialized so just return 0
            size = 0;
        }
        return size;
    }

The code is complaining about the base.SetObject call (with the EstimateObjectSize) method. I understand that I need to change my object, and having read that document that Mark posted, I still am not sure what changes need to be done. It seems as if the SetObject method has changed from holding content to holding some sort of event, and I can't wrap my head around how this is supposed to work. I'm sorry for the vague/generic original post, I'll try to be more specific in the future.

Thanks for your help!