/// <summary> /// 添加索引 /// </summary> /// <param name="index"></param> /// <returns></returns> public bool AddIndex(ICacheIndex index) { lock (_indexs) { if (_indexDiction.ContainsKey(index.IndexName)) { CacheLog.LogError(string.Format("尝试添加重复的索引【{0}】{1},表【{2}】", index.IndexName, index.IndexType, this.TableName)); throw new Exception(string.Format("索引名称重复:{0}", index.IndexName)); } _indexDiction[index.IndexName] = index; _indexs.Add(index); if (index.IndexType == IndexType.唯一索引) { if (_uniqueIndex == null) { _uniqueIndex = index; } else { CacheLog.LogError(string.Format("尝试重复添加唯一索引【{0}】(原{1}),表【{2}】", index.IndexName, _uniqueIndex.IndexName, this.TableName)); throw new Exception(string.Format("唯一索引已存在:{0},重复设置值:{1}", _uniqueIndex.IndexName, index.IndexName)); } } DataBlock block = new DataBlock(index, _uniqueIndex); _dataRegion.Add(index.IndexName, block); } return(true); }
public ISet <IEntry <K, V> > FilterEntries <TProjection>(ICacheIndex <K, V, TProjection> cacheIndex, IEntryProcessor <K, IFilterArgument <V, TProjection>, bool> filter) { var index = (InMemoryCacheIndex <K, V, TProjection>)cacheIndex; var entries = this.dict.Select(kvp => new InMemoryEntry <K, IFilterArgument <V, TProjection> >(kvp.Key, new InMemoryFilterArgument <V, TProjection>(kvp.Value, index.Projector.Project(new InMemoryEntry <K, V>(kvp.Key, kvp.Value, true))), true)); return(new HashSet <IEntry <K, V> >(entries.Select(e => new InMemoryEntry <K, V>(e.Key, e.Value.Value, e.IsPresent)))); }
public void Remove(ICacheIndex <string, string> cacheIndex) { if (!cacheIndeces.Contains(cacheIndex)) { return; } cacheIndeces.Add(cacheIndex); }
public ISet <IEntry <K, V> > FilterEntries <TProjection>(ICacheIndex <K, V, TProjection> cacheIndex, TProjection value) { var index = (InMemoryCacheIndex <K, V, TProjection>)cacheIndex; var entries = this.dict.Select(kvp => new InMemoryEntry <K, V>(kvp.Key, kvp.Value, true)); var results = entries.Select(entry => new { Entry = entry, Projection = index.Projector.Project(entry) }).Where((pair) => pair.Projection.Equals(value)); return(new HashSet <IEntry <K, V> >(results.Select(result => result.Entry))); }
protected void Id <V>(Expression <Func <T, V> > expression) { MemberExpression memberExpression = GetMemberExpression(expression); Type t = typeof(CacheIndex <,>).MakeGenericType(typeof(T), ((PropertyInfo)memberExpression.Member).PropertyType); ICacheIndex <T> index = (ICacheIndex <T>)FastActivator.Create(t, expression); _indices.Add(index); }
IDictionary GetInvertedIndex(IDictionary mapIndexes) { ICacheIndex index = (ICacheIndex)mapIndexes[ValueExtractor]; return(index != null ? index.IndexContents : null); }
/// <summary> /// Construct an IndexAdapter. /// </summary> /// <param name="index">The ICacheIndex being wrapped.</param> public IndexAdapter(ICacheIndex index) { m_index = index; }
/// <summary> /// Ensure an ICacheListener for the given index. The listener will /// route the cache events into the corresponding ICacheIndex calls. /// </summary> /// <param name="index">The index.</param> /// <returns>A listener for given index.</returns> protected static ICacheListener EnsureListener(ICacheIndex index) { return(index is CacheListenerSupport.ISynchronousListener ? (ICacheListener)index : new IndexAdapter(index)); }
public IndexWrapper(ICache <TEntity> cache, PropertyInfo property) { this.property = property; this.index = cache.CreateIndex(this.GetValue); }
/// <summary> /// 数据块 /// </summary> /// <param name="index">数据块索引</param> /// <param name="uniqueIndex">唯一索引</param> public DataBlock(ICacheIndex index, ICacheIndex uniqueIndex) { _index = index; _uniqueIndex = uniqueIndex; }