Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cache types serialization friendly #1776

Merged
merged 4 commits into from
Jul 2, 2018
Merged

Make cache types serialization friendly #1776

merged 4 commits into from
Jul 2, 2018

Conversation

maca88
Copy link
Contributor

@maca88 maca88 commented Jun 26, 2018

Here is an attempt to make the serialization of cache types easier in order to support other serializers like XmlSerializer, DataContractSerializer and others. I've added WIP in the title as the current tests are failing because of types that don't have a proper cacheable representation, which is covered by #1765. There is a limitation when a XmlSerializer is used as it does not support DateTimeOffset and TimeSpan types, which I wouldn't worry too much as DataContractSerializer should be the preferred serializer for xml as it is faster.

@hazzik
Copy link
Member

hazzik commented Jun 26, 2018

XmlSerializer ... does not support DateTimeOffset and TimeSpan types

Implement IXmlSerializable?

@fredericDelaporte
Copy link
Member

Should we bother supporting xml serialization at all? XML adds a big overhead to the data size, it is an ill suited format for caching in my opinion.

@maca88
Copy link
Contributor Author

maca88 commented Jun 27, 2018

Implement IXmlSerializable?

That is not possible, if you try that you will get an exception: 'NHibernate.Cache.Entry.CacheEntry' cannot be IXmlSerializable and have DataContractAttribute attribute. DataContract and DataMember attributes were added because Json.net also supports them so that only the members that have a DataMember attribute will be serialized, otherwise also properites with just a public getter will be serialized (e.g. CacheLock.IsLock). In order to avoid having something partially supported we could remove the added XmlInclude attributes. About the KnownType attributes, they can be also removed as they can be provided as the second argument of the DataContractSerializer constructor. So we have to following options:

  • Leave as it is
  • Remove the XmlInclude attributes
  • Remove the XmlInclude and KnownType attributes
  • Remove all added attributes
  • Remove KnownType, DataContract and DataMember attributes and implement IXmlSerializable

For me the first three are all fine, keeping the DataContract and DataMember attributes in order to control the serialization.

Should we bother supporting xml serialization at all?

Not really, I've added the XmlInclude and KnownType attributes by the way and I wouldn't mind if we remove them.

@hazzik
Copy link
Member

hazzik commented Jun 27, 2018

Number 3 please

@fredericDelaporte
Copy link
Member

2 or 3. Keeping the KnowType reduces the knowledge required to serialize things. Removing them avoids to have to maintain them. I am more in favor of 2 than 3, but I am ok with 3 too.

@maca88
Copy link
Contributor Author

maca88 commented Jun 28, 2018

Then 3 it is.

@maca88 maca88 changed the title WIP Make cache types serialization friendly Make cache types serialization friendly Jun 28, 2018
@hazzik
Copy link
Member

hazzik commented Jun 28, 2018

Stupid "GitHub-flavored markdown", I did not mean to write in bold my previous comment. What I meant is "Number 3 please". But, because because hash followed by a number would be interpreted as a issue/pr number. And because hash was the first character of the line it has been interpreted as a header.

@@ -11,7 +11,7 @@ public class StructuredCollectionCacheEntry : ICacheEntryStructure
public virtual object Structure(object item)
{
var entry = (CollectionCacheEntry)item;
return new List<object>(entry.State);
return new List<object>((object[])entry.DisassembledState);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the //TODO: assumes all collections disassemble to an array! has moved here indeed.

@@ -8,7 +8,7 @@ public class StructuredMapCacheEntry : ICacheEntryStructure
public object Structure(object item)
{
CollectionCacheEntry entry = (CollectionCacheEntry)item;
object[] state = entry.State;
object[] state = (object[])entry.DisassembledState;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the //TODO: assumes all collections disassemble to an array! has moved here indeed.

And here too. Then why not keeping it in the CollectionCacheEntry class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I got confused as IPersistentCollection.InitializeFromCache and IPersistentCollection.Disassemble are using object which I think it should be changed to object[] in the future as all implementations are casting/returning it.

@fredericDelaporte fredericDelaporte merged commit 9f2997c into nhibernate:master Jul 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants