コード例 #1
0
ファイル: AttributeIndex.cs プロジェクト: shozibabbas/NCache
        public virtual void AddToIndex(object key, object value)
        {
            lock (_mutex)
            {
                QueryItemContainer    container       = (QueryItemContainer)value;
                CacheEntry            entry           = container.Item;
                Hashtable             attributeValues = container.ItemArrtributes;
                IDictionaryEnumerator valuesDic       = attributeValues.GetEnumerator();
                INodeReference        keyNode;
                while (valuesDic.MoveNext())
                {
                    string indexKey = (string)valuesDic.Key;
                    object val      = valuesDic.Value;

                    string      storeName = indexKey;
                    IIndexStore store     = IndexTable[indexKey] as IIndexStore;
                    keyNode = null;

                    if (store == null)
                    {
                        if (indexKey == TAG_INDEX_KEY)
                        {
                            Type genericType =
                                typeof(RBStore <>).MakeGenericType(
                                    Common.MemoryUtil.GetDataType(Common.MemoryUtil.Net_System_String));
                            store =
                                (IIndexStore)
                                Activator.CreateInstance(genericType,
                                                         new object[]
                                                         { CacheName, Common.MemoryUtil.Net_System_String, indexKey, _haveDuplicateKeys });
                            IndexTable[indexKey] = store;
                        }
                        else
                        {
                            string namedTagIndexKey = ConvertToNamedTagKey(indexKey);
                            storeName = namedTagIndexKey;
                            store     = IndexTable[namedTagIndexKey] as IIndexStore;


                            if (store == null)
                            {
                                String storeDataType = String.Empty;
                                if (val != null)
                                {
                                    Type type = val.GetType();
                                    storeDataType = type.FullName;
                                }
                                Type genericType =
                                    typeof(RBStore <>).MakeGenericType(Common.MemoryUtil.GetDataType(storeDataType));
                                store =
                                    (IIndexStore)
                                    Activator.CreateInstance(genericType,
                                                             new object[]
                                                             { CacheName, storeDataType, namedTagIndexKey, _haveDuplicateKeys });

                                IndexTable.Add(namedTagIndexKey, store);
                            }
                        }
                    }

                    if (store != null)
                    {
                        long prev = store.IndexInMemorySize;

                        if (val != null)
                        {
                            keyNode = (INodeReference)store.Add(val, key);
                        }
                        _attributeIndexSize += store.IndexInMemorySize - prev;
                    }

                    storeName = StringPool.PoolString(storeName);

                    IndexInformation info;

                    if (entry.IndexInfo != null)
                    {
                        info = entry.IndexInfo;
                    }
                    else
                    {
                        info = new IndexInformation();
                    }
                    long prevSize = info.IndexInMemorySize;

                    info.Add(storeName, store, keyNode);

                    _keyIndexInformationSize += info.IndexInMemorySize - prevSize;
                    entry.IndexInfo           = info;
                }
            }
        }