public bool DropIndex(string memberPath) { IndexWrapper index; if (IndexCache.TryGetValue(memberPath, out index)) { IndexCache.Remove(memberPath); Remove(memberPath, _ => true); index.Drop(); return(true); } return(false); }
/// <summary> /// Returns the indexed children for this user from the cache. Caches them if not already there. /// </summary> /// <param name="user">The user.</param> /// <param name="indexBy">The index by.</param> /// <returns>IEnumerable{BaseItem}.</returns> private IEnumerable <BaseItem> GetIndexedChildren(User user, string indexBy) { List <BaseItem> result; var cacheKey = user.Name + indexBy; IndexCache.TryGetValue(cacheKey, out result); if (result == null) { //not cached - cache it Func <User, IEnumerable <BaseItem> > indexing; IndexByOptions.TryGetValue(indexBy, out indexing); result = BuildIndex(indexBy, indexing, user); } return(result); }
public bool EnsureIndex(IndexDefinition indexDefinition) { // Try to not rebuild index, so we check if there exists an equal defintion already IndexWrapper existing; if (IndexCache.TryGetValue(indexDefinition.Path, out existing)) { if (indexDefinition.Options.Equals(existing.IndexDefinition.Options)) { // phew, existing index was already matching. bail out return(false); } DropIndex(indexDefinition.Path); } // An index can not both exclude certain values and at the same time include certain values var hasIncludeValues = (indexDefinition.Options.IncludeValues != null) && (indexDefinition.Options.IncludeValues.Length > 0); var hasExcludeValues = (indexDefinition.Options.ExcludeValues != null) && (indexDefinition.Options.ExcludeValues.Length > 0); if (hasIncludeValues && hasExcludeValues) { throw new KiwiDbException("An index can not have an exclusion list and an inclusion list at the same time."); } var index = new IndexWrapper(this, indexDefinition) { IsChanged = true }; IndexCache.Add(indexDefinition.Path, index); Insert(indexDefinition.Path, JSON.FromObject(indexDefinition)); // rebuild index foreach (var record in MasterTable.Scan()) { UpdateIndex(record.Key, null, record.Value); } return(true); }
public IIndex GetIndex(string memberPath) { IndexWrapper indexWrapper; return(IndexCache.TryGetValue(memberPath, out indexWrapper) ? indexWrapper : null); }