Project Description
Implementation of Enterprise Library 5 Caching using ProtoBuf.NET Isolated Storage Backing Store

Introduction

In my last project I have tried to use Enterprise Library 5 Caching with Isolated Backed Store. All went well except reading from data takes 5 sec (which I wanted to cache) and deserialising from Isolated BackedStore took 6. Defeats the whole purpose of caching, doesnt it?

When I put some performance counters around, I found out that most of the time is spent on deserializing the cache item while CacheManager initializes.

So after reading about different serialization techniques (which I came across this StackOverflow article:http://stackoverflow.com/questions/2000933/protocol-buffers-versus-json-or-bson I chose ProtoBuf.NET in the end.

Implementation

Extending the Backing Store is quite straight forward as whole Enterprise Library is designed to an interface. This great MSDN Article:http://msdn.microsoft.com/en-us/library/ff664546%28v=pandp.50%29 has all the info you need to come up with your own Caching extensions.

ProtoBuf.NET + IsolatedStorageBackingStore

Note: Solution might need a bit of clean up as I have done quick and dirty way of copy and paste!!!

Below is the steps/approach I have taken to flesh out ProtoBuf based IsolatedStorageBackingStore
  1. First get a sourcecode of EntLib from here:http://www.microsoft.com/en-us/download/details.aspx?id=15104
  2. You will have to inherit from BaseBackingStore and/or IBackingStore and provide your own logic for Serialization
    1. That's where IsolatedStorageProtoBufCacheItemField comes into play. This is the copy of the IsolatedStorageCacheItemField class but overrides Read/Write logic to plug in ProtoBuf.
    2. Once extra thing I had to do was to include Type information in the cache so that when we try to deserialize it back, you can pass the type information to ProtoBuf.NET Serializer
  3. Solution contains some tests around how to write and read back from caching store.

Happy coding!

To-do list

  1. RefreshAction parameter needs Serializable attribute which makes it difficult to include as you will have to mark up most of the dependent libraries as well. I would like to extend CacheManager so that I can reassign RefreshAction after service initialization

Useful Links

Description Link
Enterprise Library 5.0 Binary Download http://www.microsoft.com/en-us/download/details.aspx?id=15104
EntLib 5 Online Documentation http://msdn.microsoft.com/en-us/library/ff632023.aspx
ProtoBuf.NET http://code.google.com/p/protobuf-net

Last edited Jul 2, 2012 at 8:58 PM by bluecreststudio, version 10