Example #1
0
        public ICacheTable <TKey> GetOrCreateTable <TKey>(string tableName, out bool createdNew, IEqualityComparer <TKey> keyComparer = null)
        {
            if (tableName.IsNullOrWhiteSpace())
            {
                throw new PileCacheException(StringConsts.ARGUMENT_ERROR + "GetTable(tableName=null|empty)");
            }

            ensureRunning("GetOrCreateTable");

            LocalCacheTable <TKey> result;

            var tbl = m_Tables[tableName];

            if (tbl != null)
            {
                result = tbl as LocalCacheTable <TKey>;
                if (result == null)
                {
                    throw new PileCacheException(StringConsts.PILE_CACHE_TBL_KEYTYPE_MISMATCH_ERROR.Args(tableName,
                                                                                                         tbl.GetType().DisplayNameWithExpandedGenericArgs(),
                                                                                                         typeof(LocalCacheTable <TKey>).DisplayNameWithExpandedGenericArgs()));
                }
                if (keyComparer != null && result.KeyComparer != keyComparer)
                {
                    throw new PileCacheException(StringConsts.PILE_CACHE_TBL_KEYCOMPARER_MISMATCH_ERROR.Args(tableName,
                                                                                                             result.KeyComparer != null ? result.KeyComparer.GetType().FullName : StringConsts.NULL_STRING,
                                                                                                             keyComparer != null ? keyComparer.GetType().FullName : StringConsts.NULL_STRING));
                }
                createdNew = false;
                return(result);
            }

            lock (m_TablesLock)
            {
                tbl = m_Tables[tableName];
                if (tbl != null)
                {
                    result = tbl as LocalCacheTable <TKey>;
                    if (result == null)
                    {
                        throw new PileCacheException(StringConsts.PILE_CACHE_TBL_KEYTYPE_MISMATCH_ERROR.Args(tableName,
                                                                                                             tbl.GetType().DisplayNameWithExpandedGenericArgs(),
                                                                                                             typeof(LocalCacheTable <TKey>).DisplayNameWithExpandedGenericArgs()));
                    }
                    if (keyComparer != null && result.KeyComparer != keyComparer)
                    {
                        throw new PileCacheException(StringConsts.PILE_CACHE_TBL_KEYCOMPARER_MISMATCH_ERROR.Args(tableName,
                                                                                                                 result.KeyComparer != null ? result.KeyComparer.GetType().FullName : StringConsts.NULL_STRING,
                                                                                                                 keyComparer != null ? keyComparer.GetType().FullName : StringConsts.NULL_STRING));
                    }
                    createdNew = false;
                    return(result);
                }

                result = new LocalCacheTable <TKey>(this, tableName, keyComparer, m_TableOptions[tableName] ?? m_DefaultTableOptions);
                m_Tables.Register(result);
                createdNew = true;
                return(result);
            }
        }
Example #2
0
            public _bucket(LocalCacheTable <TKey> table)
            {
                Table = table;
                var capacity = (int)(table.m_Options.InitialCapacity) / BUCKETS;

                capacity = IntMath.GetPrimeCapacityOfAtLeast(capacity);
                Entries  = makeEntriesArray(capacity);
            }
Example #3
0
 public _bucket(LocalCacheTable<TKey> table)
 {
   Table = table;
   var capacity = (int)(table.m_Options.InitialCapacity) / BUCKETS;
   capacity = IntMath.GetPrimeCapacityOfAtLeast(capacity);
   Entries = makeEntriesArray(capacity); 
 }