Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default serialization used by the ASP.net HttpRuntime.Cache

Just wondering if anyone knows definitively what the default serialization used by the ASP.net HttpRuntime.Cache is? Is it Binary, XML, something else?

I ask because I have a situation where I am populating a generic List with multiple objects of the same custom type. The custom type is a POCO, there is nothing special about it. All of its properties are public with { get; set; }, it is public, it has no inheritance, it has no interfaces. In fact it is much less complicated than many other objects which we are caching which work without issue. I have tried adding the [Serializable] attribute to the custom class and it has no effect.

I add the list to the cache with a unique key. The list has been verified as populated before it is inserted into the cache, the objects in the list have been verified as populated as well. But when the list is pulled back out of the cache it is an empty list (NOT NULL), it simply has no items in it. This means that the list is being added to the cache and is retrievable but for some reason the cache is having issues serializing the objects in the list.

I just find this freaky weird since I have another list of custom objects which are much more complicated (consisting of Inheritance, Interfaces, and also containing Properties which are generic lists of other complex objects) and the caching of those lists work without issue.

Both the working and non-working list are being managed in C# classes outside of the ASP.net user controls which consume the cached data. Both of these cache handling classes call the exact same Cache Manager class singleton instance which wraps the HttpRuntime.Cache to provide typed methods for pull and pushing objects into the cache.

Anyone have any ideas what could cause this to happen. The only thing I can thin of is that the 'Blurb' property of the Document object can potentially contain HTML, but if ASP.net uses binary serialization for the cache I don't see how this would do anything.

Here is the class

public class Document
{
    public string ContentTypeId { get; set; }
    public string ContentId { get; set; }
    public bool IsCustom { get; set; }
    public Language DocLanguage { get; set; }
    public string RegularTitle { get; set; }
    public string InvertedTitle { get; set; }
    public string Blurb { get; set; }
}  

Here is the subclass used in the Language Property

public class Language
{
    public string Name { get; set; }
    public string Code { get; set; }
}
like image 425
Schleichermann Avatar asked Jan 29 '10 15:01

Schleichermann


1 Answers

According to Reflector, HttpRuntime.Cache doesn't serialize data at all, it merely stores it in memory in a Hashtable.

You say you wrap calls to the cache inside your own singleton object. Why do you do this? HttpRuntime.Cache is a static property, and so your wrapper methods can be static too.

like image 152
Christian Hayter Avatar answered Nov 15 '22 04:11

Christian Hayter