Last active
August 29, 2015 14:07
-
-
Save nickheppleston/a414fb76eaa7a2dc27be to your computer and use it in GitHub Desktop.
Revisions
-
nickheppleston revised this gist
Oct 13, 2014 . 1 changed file with 1 addition and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,15 +4,9 @@ * http://msdn.microsoft.com/en-us/library/azure/dn690524.aspx#Objects */ using System.IO; using System.Runtime.Serialization.Formatters.Binary; namespace AzureRedisCacheSample { public static class CacheSerializer -
nickheppleston renamed this gist
Oct 13, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
nickheppleston revised this gist
Oct 13, 2014 . 1 changed file with 33 additions and 32 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ /* * A simple generic Serialization Helper allowing custom .Net types to be stored * in the Azure Redis Cache. Inspired by the sample at: * http://msdn.microsoft.com/en-us/library/azure/dn690524.aspx#Objects */ @@ -15,35 +15,36 @@ namespace AzureRedisCacheSample { public static class CacheSerializer { public static byte[] Serialize(object o) { if (o == null) { return null; } BinaryFormatter binaryFormatter = new BinaryFormatter(); using (MemoryStream memoryStream = new MemoryStream()) { binaryFormatter.Serialize(memoryStream, o); byte[] objectDataAsStream = memoryStream.ToArray(); return objectDataAsStream; } } public static T Deserialize<T>(byte[] stream) { if (stream == null) return (default(T)); BinaryFormatter binaryFormatter = new BinaryFormatter(); using (MemoryStream memoryStream = new MemoryStream(stream)) { T result = (T)binaryFormatter.Deserialize(memoryStream); return result; } } } } -
nickheppleston created this gist
Oct 13, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ /* * A simple Serialization Helper allowing custom .Net types to be stored * in the Azure Redis Cache. Inspired by the sample at: * http://msdn.microsoft.com/en-us/library/azure/dn690524.aspx#Objects */ using StackExchange.Redis; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; using System.Text; using System.Threading.Tasks; namespace AzureRedisCacheSample { public static class CacheSerializer { public static byte[] Serialize(object o) { if (o == null) { return null; } BinaryFormatter binaryFormatter = new BinaryFormatter(); using (MemoryStream memoryStream = new MemoryStream()) { binaryFormatter.Serialize(memoryStream, o); byte[] objectDataAsStream = memoryStream.ToArray(); return objectDataAsStream; } } public static T Deserialize<T>(byte[] stream) { if (stream == null) return (default(T)); BinaryFormatter binaryFormatter = new BinaryFormatter(); using (MemoryStream memoryStream = new MemoryStream(stream)) { T result = (T)binaryFormatter.Deserialize(memoryStream); return result; } } } }