Hi Pavel.


Thanks for the pointer, it looks like a good option. I’ll read into
IBinarizable et al.



Thanks,

Raymond



*From:* Pavel Tupitsyn [mailto:ptupit...@apache.org]
*Sent:* Thursday, July 27, 2017 12:00 AM
*To:* user@ignite.apache.org
*Subject:* Re: Cache item factory



Hi Raymond,



You can have complete control over deserialization with IBinarizable
interface:

https://apacheignite-net.readme.io/docs/serialization#section-ibinarizable



ReadBinary method takes IBinaryReader, which internally operates directly
on unmanaged memory stream,

so you can eliminate any unwanted GC costs, use object pools, etc.



Let me know if you need help on this with your particular use case.



Thanks,

Pavel



On Wed, Jul 26, 2017 at 12:53 PM, Raymond Wilson <raymond_wil...@trimble.com>
wrote:

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