Hi,


I would like to control the way objects are created in response to
ICache.Get() methods.



For instance given a cache defined like this:



    ICache<String, MemoryStream> MyCache;



I would like to provide a factory to create the MemoryStream instance when
Ignite needs to create an instance to deserialise a cache entry into, eg:



    MyCache = MyGrid.GetOrCreateCache<String, MemoryStream>(new
CacheConfiguration() { cacheItemFactory = new CacheItemFactory<MemoryStream>()
} );



Where:



    public class CacheItemFactory<T> where T : new()

    {

        public T NewCacheItem()

        {

            return new T();

        }

    }



Then:



    MemoryStream ms = MyCache.Get(“key”)



Will result in my item factory being asked to create the MemoryStream
instance.



This means I can control the creation of objects representing cached items
when they move from the Ignite cache into my local context for access.



I have used MemoryStream as an example of an object type that is relatively
expensive to create in C# and can incur significant GC penalties. There are
others such as cache items that represent arrays of elements etc.



In the MemoryStream case this means I could do something like this to
improve performance and reduce GC interruptions, from
http://adamsitnik.com/Array-Pool/:



    public class MyCacheItemFactory<T> where T : new()

    {

        public T NewCacheItem()

        {

            return ArrayPool<MemoryStream>.Shared;

        }

    }



Or even this, from
https://github.com/Microsoft/Microsoft.IO.RecyclableMemoryStream



    using Microsoft.IO.RecyclableMemoryStream;



    public class MyCacheItemFactory<T> where T : new()

    {

        static RecyclableMemoryStreamManager manager = new
RecyclableMemoryStreamManager();



        public T NewCacheItem()

        {

            return manager.GetStream();

        }

    }



For further background on this see http://adamsitnik.com/Array-Pool/



Does this facility already exist in Ignite 2.0, or is on backlog?



I have checked through the CacheConfiguration but have not found this kind
of capability present.



Thanks,

Raymond.

Reply via email to