コード例 #1
0
 public DictionaryCacheData(int partitionCount, IEqualityComparer <TKey> keyComparer,
                            ICacheDataSerializer serializer, int initialCap = 0) : base(partitionCount, keyComparer)
 {
     _serializer = serializer;
     _data       = new Dictionary <TKey, TValue> [TotalSync];
     for (var i = 0; i < TotalSync; i++)
     {
         _data[i] = new Dictionary <TKey, TValue>(initialCap, keyComparer);
     }
     _alreadySerialized = false;
 }
コード例 #2
0
 public HashSetCacheData(int partitionCount, IEqualityComparer <TKey> keyComparer, ICacheDataSerializer serializer)
     : base(partitionCount, keyComparer)
 {
     _serializer = serializer;
     _data       = new HashSet <TKey> [TotalSync];
     for (var i = 0; i < TotalSync; i++)
     {
         _data[i] = new HashSet <TKey>(keyComparer);
     }
     _alreadySerialized = false;
 }
コード例 #3
0
        private AsyncCacheData <TKey, TValue> CreateCacheDataInstance(ICacheConfigProfile config,
                                                                      ICacheDataSerializer serializer)
        {
            var partitions = StaticCalls.AdjustPartitionCount(config.PartitionCount);

            if (!config.KeyIsValue)
            {
                return(new DictionaryCacheData <TKey, TValue>(partitions, _keyComparer, serializer));
            }
            if (typeof(TKey) == typeof(TValue))
            {
                return(new HashSetCacheData <TKey>(partitions, _keyComparer, serializer) as AsyncCacheData <TKey, TValue>);
            }
            throw new AsyncCacheException(AsyncCacheErrorCode.InvalidConfig,
                                          $"Config sets {nameof(config.KeyIsValue)} = true. But TKey and TValue not same type.");
        }
コード例 #4
0
 private AsyncCacheData <TKey, TValue> CreateAdditionalCacheDataInstance(ICacheConfigProfile config,
                                                                         ICacheDataSerializer serializer)
 {
     if (config.AdType == AdditionalData.None)
     {
         return(new EmptyCacheData <TKey, TValue>(0, null));
     }
     if (!config.KeyIsValue)
     {
         return(new DictionaryCacheData <TKey, TValue>(1, _keyComparer, serializer));
     }
     if (typeof(TKey) == typeof(TValue))
     {
         return(new HashSetCacheData <TKey>(1, _keyComparer, serializer) as AsyncCacheData <TKey, TValue>);
     }
     throw new AsyncCacheException(AsyncCacheErrorCode.InvalidConfig,
                                   $"Config sets {nameof(config.KeyIsValue)} = true. But TKey and TValue not same type.");
 }