protected override void PutFileData(CacheIndex index, int fileId, byte[] data, CacheFileInfo?info) { if (this.ReadOnly) { throw new CacheException("Can't write data in readonly mode."); } var dbTable = "cache"; if (index == CacheIndex.ReferenceTables) { index = (CacheIndex)fileId; dbTable = "cache_index"; fileId = 1; } lock (this._ioLock) { if (!this._connections.Keys.Contains(index)) { this.OpenConnection(index, true); } var connection = this._connections[index]; using var command = connection.CreateCommand(); command.CommandText = $"INSERT OR REPLACE INTO {dbTable} (KEY, DATA, VERSION, CRC) VALUES (@key, @data, @version, @crc)"; command.Parameters.AddWithValue("key", fileId); command.Parameters.AddWithValue("data", data); command.Parameters.AddWithValue("version", info?.Version ?? DateTimeOffset.UtcNow.ToUnixTimeSeconds()); command.Parameters.AddWithValue("crc", info?.Crc ?? 0); command.ExecuteNonQuery(); } }
private void OnCacheUpdated(object sender, DataEventArgs <string> e) { CacheIndex cacheIndex = this.GetCacheIndex(e.Data); if (cacheIndex != null) { double?timecode = this.ExtractTimecode(e.Data, cacheIndex.Asset.StartPosition); if (timecode.HasValue && !cacheIndex.Timecodes.Contains(timecode.Value)) { IDictionary <double, double> cacheSnapshot = GenerateCacheSnapshot( cacheIndex.Cache, cacheIndex.Timecodes, timecode.Value, cacheIndex.Asset.DurationInSeconds); if (cacheSnapshot.Count == 1) { cacheIndex.Timecodes.Add(timecode.Value); cacheIndex.Timecodes.Sort(); double progress = cacheSnapshot.Keys.ElementAt(0); double offset = cacheSnapshot.Values.ElementAt(0); cacheIndex.Cache.Add(progress, offset); Asset asset = cacheIndex.Asset as Asset; if (asset != null) { this.InvokeCacheUpdated(progress, offset, asset); } } } } }
public void UpdateCacheItemTest() { _pool.Register <TestTable>(); CacheIndex index = new CacheIndex() { IndexName = "主键测试", IndexType = IndexType.唯一索引, GetIndexKey = GetKey }; _pool.Get <TestTable>().AddIndex(index); List <ICacheIndex> indexs = _pool.Get <TestTable>().GetAllIndexs(); TestCacheModel model = new TestCacheModel() { ID = 1, Name = "测试" }; _pool.Get <TestTable>().Add(model); TestCacheModel updateModel = new TestCacheModel() { ID = 1, Name = "测试1" }; _pool.Get <TestTable>().Update(updateModel); List <ICacheItem> item = _pool.Get <TestTable>().Get(model.ID.ToString()); TestCacheModel queryRlt = item[0] as TestCacheModel; Assert.AreEqual(updateModel.Name, queryRlt.Name); }
public CacheFile GetFile(CacheIndex index, int fileId) { var fileInfo = this.GetFileInfo(index, fileId); var fileData = this.GetFileData(index, fileId, fileInfo); return(this.FileDecoder.DecodeFile(fileData, fileInfo)); }
private IEnumerable <string> GetExistingFilePaths(CacheIndex cacheIndex, int fileId) { return(Directory .EnumerateFiles(this.GetIndexDirectory(cacheIndex), $"{fileId}*") // Filter out false-positivies like 2345 when looking for 234.ext .Where(matchedFilePath => Regex.IsMatch(matchedFilePath, $@"[/\\]{fileId}(\..+)?$"))); }
/// <summary> /// Returns the given data converted to sectors. <see cref="Position" /> and <see cref="NextSectorPosition" /> /// must still be set before writing them out to the data file. /// </summary> public static IEnumerable <Sector> FromData(byte[] data, CacheIndex cacheIndex, int fileId) { var extended = Sector.IsExtendedSector(fileId); var remaining = data.Length; var chunkId = 0; while (remaining > 0) { var sector = new Sector { ChunkIndex = chunkId++, Index = cacheIndex, FileId = fileId }; var sectorDataLength = extended ? Sector.ExtendedDataLength : Sector.StandardDataLength; var dataLength = Math.Min(sectorDataLength, remaining); var sectorData = data.Skip(data.Length - remaining).Take(dataLength); // Fill sector if (dataLength < sectorDataLength) { sectorData = sectorData.Concat(Enumerable.Repeat((byte)0, sectorDataLength - dataLength)); } sector.Payload = sectorData.ToArray(); remaining -= dataLength; yield return(sector); } }
/// <summary> /// Gets the resource response. /// </summary> /// <param name="uri">The URI of the request.</param> /// <param name="args">The arguments to be used on the request.</param> /// <returns></returns> public override ResourceResponse GetResponse(string uri, NetworkResourceArguments args) { ResourceResponseCache response = new ResourceResponseCache(uri, args); // find the item in the cache index CacheIndex cacheIndex = CacheIndexMap.GetFromUri(uri); CacheIndexItem cacheIndexItem = cacheIndex.Get(uri); // ensure cache item is current response.ReturnStatus = cacheIndex.EnsureCurrentCache(cacheIndexItem, args); // store local references to cache index and item to prevent having to look up // values again later. response.CacheIndex = cacheIndex; response.CacheIndexItem = cacheIndexItem; // populate response data collection with cache index values; response.Data.Add("RelativeUri", cacheIndexItem.RelativeUri); response.Data.Add("AttemptToRefresh", cacheIndexItem.AttemptToRefresh.ToString()); response.Data.Add("Downloaded", cacheIndexItem.Downloaded.ToString()); response.Data.Add("Expiration", cacheIndexItem.Expiration.ToString()); response.Data.Add("IsExpired", cacheIndexItem.IsExpired.ToString()); response.Data.Add("IsStale", cacheIndexItem.IsStale.ToString()); response.Data.Add("ETag", cacheIndexItem.ETag); return(response); }
private static void ProcessAddList(List <CacheIndexInternal> internalIndexList, List <IndexItem> cappedDeleteItemList, CacheIndex clientIndex, IndexStoreContext storeContext, IndexTypeMapping indexTypeMapping) { #region Add new items to each internalIndex Index indexInfo; InternalItemComparer comparer; int searchIndex; PerformanceCounters.Instance.SetCounterValue( PerformanceCounterEnum.AddList, indexTypeMapping.TypeId, clientIndex.AddList.Count); foreach (CacheIndexInternal cacheIndexInternal in internalIndexList) { indexInfo = indexTypeMapping.IndexCollection[cacheIndexInternal.InDeserializationContext.IndexName]; comparer = new InternalItemComparer(indexInfo.PrimarySortInfo.IsTag, indexInfo.PrimarySortInfo.FieldName, indexInfo.PrimarySortInfo.SortOrderList); if (clientIndex.AddList.Count > 0) { foreach (IndexDataItem addItem in clientIndex.AddList) { searchIndex = cacheIndexInternal.Search(addItem); if (searchIndex > -1) { UpdateExistingIndexItem(clientIndex, cacheIndexInternal, indexInfo, addItem, searchIndex, storeContext, comparer); } else { AddNewItem(clientIndex, cacheIndexInternal, indexInfo, addItem, storeContext, comparer); #region IndexSize Capping if (indexInfo.MaxIndexSize > 0 && cacheIndexInternal.Count > indexInfo.MaxIndexSize) { int deleteIndex = indexInfo.TrimFromTail ? cacheIndexInternal.Count - 1 : 0; //Add item to a list to delete it from the Data Store cappedDeleteItemList.Add(InternalItemAdapter.ConvertToIndexItem(cacheIndexInternal.GetItem(deleteIndex), cacheIndexInternal.InDeserializationContext)); //Delete from Index Store cacheIndexInternal.DeleteItem(deleteIndex, false); } #endregion } } } //Update metadata if (clientIndex.UpdateMetadata && indexTypeMapping.IndexCollection[cacheIndexInternal.InDeserializationContext.IndexName].MetadataPresent) { cacheIndexInternal.Metadata = clientIndex.Metadata; } } #endregion }
/// <summary> /// Gets printable CacheIndex. /// </summary> /// <param name="clientIndex">client index.</param> /// <param name="tagHashCollection">tag Hash Collection.</param> /// <param name="typeId">type id.</param> /// <returns></returns> internal static string GetPrintableCacheIndex(CacheIndex clientIndex, TagHashCollection tagHashCollection, short typeId) { StringBuilder logStr = new StringBuilder(); logStr.Append(Environment.NewLine).Append("Client Index Info").Append(Environment.NewLine); int itemCount; logStr.Append("IndexId : ").Append(IndexCacheUtils.GetReadableByteArray(clientIndex.IndexId)).Append(Environment.NewLine); logStr.Append("Metadata : ").Append(clientIndex.Metadata == null ? "Null" : IndexCacheUtils.GetReadableByteArray(clientIndex.Metadata)).Append(Environment.NewLine); logStr.Append("TargetIndexName : ").Append(clientIndex.TargetIndexName).Append(Environment.NewLine); logStr.Append("IndexTagmapping : ").Append(clientIndex.IndexTagMapping == null ? "Null" : clientIndex.IndexTagMapping.Count.ToString()).Append(Environment.NewLine); if (clientIndex.IndexTagMapping != null && clientIndex.IndexTagMapping.Count > 0) { logStr.Append("IndexTagmapping Items : "); foreach (var indexTag in clientIndex.IndexTagMapping) { logStr.Append("IndexName : ").Append(indexTag.Key).Append(" Tags : "); foreach (var tag in indexTag.Value) { logStr.Append(tag).Append(" , "); } } logStr.Append(Environment.NewLine); } //AddList)) if (clientIndex.AddList != null) { logStr.Append("ClientIndex.AddList.Count : ").Append(clientIndex.AddList.Count).Append(Environment.NewLine); itemCount = 0; foreach (IndexDataItem indexDataItem in clientIndex.AddList) { LogItem(logStr, indexDataItem, itemCount, tagHashCollection, typeId); } } else { logStr.Append("ClientIndex.AddList = null").Append(Environment.NewLine); } //DeleteList if (clientIndex.DeleteList != null) { logStr.Append("ClientIndex.DeleteList.Count : ").Append(clientIndex.DeleteList.Count).Append(Environment.NewLine); itemCount = 0; foreach (IndexItem indexItem in clientIndex.DeleteList) { LogItem(logStr, indexItem, itemCount, tagHashCollection, typeId); } } else { logStr.Append("ClientIndex.DeleteList = null").Append(Environment.NewLine); } return(logStr.ToString()); }
public void TestItemDefinitionFile(CacheIndex index, int fileId, int entryId, string expectedName, int expectedPropertyCount) { var itemDefinitionFile = ItemDefinitionFile.Decode( this.Fixture.JavaClientCache.GetFile(index, fileId).Entries[entryId] ); Assert.Equal(expectedName, itemDefinitionFile.Name); Assert.Equal(expectedPropertyCount, itemDefinitionFile.Properties?.Count); }
static IObservable <T> GetAndFetchLatestFromIndex <T>(this IBlobCache This, string key, Func <IObservable <T> > fetchFunc, Action <T> removedItemsCallback, Func <DateTimeOffset, bool> fetchPredicate = null, DateTimeOffset?absoluteExpiration = null, bool shouldInvalidateOnError = false) where T : CacheItem { var idx = Observable.Defer(() => This .GetOrCreateObject(key, () => CacheIndex.Create(key))) .Select(x => x.IndexKey == null ? CacheIndex.Create(key) : x) .Replay() .RefCount(); var fetch = idx .Select(x => Tuple.Create(x, fetchPredicate == null || !x.Keys.Any() || fetchPredicate(x.UpdatedAt))) .Where(predicateIsTrue => predicateIsTrue.Item2) .Select(x => x.Item1) .Select(index => index.Clear()) .SelectMany(index => fetchFunc() .Catch <T, Exception>(ex => { var shouldInvalidate = shouldInvalidateOnError ? This.InvalidateObject <CacheIndex>(key) : Observable.Return(Unit.Default); return(shouldInvalidate.SelectMany(__ => Observable.Throw <T>(ex))); }) .SelectMany(x => x.Save <T>(This, key, absoluteExpiration)) .Do(x => index.Add(key, x)) ); var cache = idx .SelectMany(index => This.GetObjects <T>(index.Keys.ToList())) .SelectMany(dict => dict.Values); return(cache.Merge(fetch) .Finally(async() => { var index = await idx; await index.Save(This); var list = index.OldKeys.Except(index.Keys); if (!list.Any()) { return; } var removed = await This.GetObjects <T>(list); foreach (var d in removed.Values) { removedItemsCallback(d); } await This.InvalidateObjects <T>(list); }) .Replay().RefCount()); }
public override byte[] GetFileData(CacheIndex index, int fileId, CacheFileInfo?info) { // Reference tables are stored as file 1 in a separate table in the database of the index. var dbTable = "cache"; if (index == CacheIndex.ReferenceTables) { index = (CacheIndex)fileId; dbTable = "cache_index"; fileId = 1; } lock (this._ioLock) { if (!this._connections.Keys.Contains(index)) { throw new CacheFileNotFoundException($"Index {(int)index} is not available."); } var connection = this._connections[index]; using var command = connection.CreateCommand(); command.CommandText = $"SELECT DATA, VERSION, CRC FROM {dbTable} WHERE KEY = @key"; command.Parameters.AddWithValue("key", fileId); using var resultReader = command.ExecuteReader(); if (!resultReader.HasRows) { throw new CacheFileNotFoundException($"File {(int)index}/{fileId} does not exist in the cache."); } resultReader.Read(); var data = (byte[])resultReader.GetValue(0); var version = resultReader.GetInt32(1); var crc = resultReader.GetInt32(2); // Version and CRC do not match data but do have to match the passed info. if (info?.Version != null && version != info.Version) { throw new DecodeException($"Retrieved version ({version}) does not match expected ({info.Version})."); } if (info?.Crc != null && crc != info.Crc) { // They actually mess around with the CRC =S var message = $"Retrieved CRC ({crc}) does not match expected ({info.Crc})."; if (crc - 1 == info.Crc) { Log.Debug(message + " (allowed)"); } else { throw new DecodeException(message); } } return(data); } }
internal void Clear() { foreach (var file in Directory.GetFiles(myCacheFolder)) { File.Delete(file); } myIndex = CacheIndex.LoadOrCreate(myIndexFile); }
public void TestDecodeEncodeFromCache(CacheIndex index) { var referenceTableFile = this._fixture.JavaClientCache.GetFile(CacheIndex.ReferenceTables, (int)index); var referenceTable = ReferenceTableFile.Decode(referenceTableFile.Data); var encodedFile = referenceTable.Encode(); Assert.True(referenceTableFile.Data.SequenceEqual(encodedFile)); }
public byte[] DownloadFileData(CacheIndex index, int fileId) { // Add the request, or get an existing one var requestKey = new Tuple <CacheIndex, int>(index, fileId); var request = this._fileRequests.GetOrAdd(requestKey, tuple => new TcpFileRequest()); Task.Run(this.ProcessRequests); return(request.WaitForCompletionAsync().Result); }
/// <summary> /// Reads the sectors /// </summary> /// <param name="index"></param> /// <param name="fileId"></param> /// <returns></returns> public byte[] ReadFileData(CacheIndex index, int fileId) { int filesize; return(this.ReadSectors(index, fileId, out filesize).Aggregate(new List <byte>(), (bytes, sector) => { bytes.AddRange(sector.Payload); return bytes; }).Take(filesize).ToArray()); }
CreateIndex <TValue>(Func <TEntity, TValue> valueGetter) { ArgumentValidator.EnsureArgumentNotNull(valueGetter, nameof(valueGetter)); // create and return the index var index = new CacheIndex <TValue>(this, valueGetter); this.indices.Add(index); return(index); }
/// <summary> /// Validates the save. /// </summary> /// <param name="clientIndex">Index of the client.</param> private static void ValidateSave(CacheIndex clientIndex) { if (clientIndex.IndexVirtualCountMapping != null && clientIndex.AddList != null && clientIndex.AddList.Count > 0 && clientIndex.DeleteList != null && clientIndex.DeleteList.Count > 0) { LoggingUtil.Log.ErrorFormat("VirtualCount cannot be set with non-empty AddList and DeleteList"); throw new Exception("VirtualCount cannot be set with non-empty AddList and DeleteList"); } }
public override byte[] GetFileData(CacheIndex index, int fileId, CacheFileInfo?info) { if (DownloaderCache.HttpInterfaceIndexes.Contains(index)) { // HTTP downloader requires file info in advance. var fileInfo = this.GetFileInfo(index, fileId); return(this._httpFileDownloader.DownloadFileData(index, fileId, fileInfo)); } return(this._tcpFileDownloader.DownloadFileData(index, fileId)); }
public static bool Available(string url) { int idx = CacheIndex.IndexOf(url); if (idx < 0) { return(false); } string filename = CacheIndex[idx - 1]; return(FileUtility.IsFileNewEnough(filename)); }
private void OnItemsPurged(object sender, DataEventArgs <IEnumerable <string> > e) { IDictionary <string, CacheIndex> updatedCache = new Dictionary <string, CacheIndex>(); foreach (string key in e.Data) { string cacheKey = key.ToUpperInvariant(); if (cacheKey.Contains("/FRAGMENTS(VIDEO=")) { string cacheIndexKey = this.assetsCacheIndex.Keys.Where(cacheKey.StartsWith).SingleOrDefault(); if (!string.IsNullOrEmpty(cacheIndexKey) && this.assetsCacheIndex.ContainsKey(cacheIndexKey)) { CacheIndex cacheIndex = this.assetsCacheIndex[cacheIndexKey]; double?timecode = this.ExtractTimecode(cacheKey, cacheIndex.Asset.StartPosition); if (timecode.HasValue && cacheIndex.Timecodes.Contains(timecode.Value)) { IDictionary <double, double> cacheSnapshot = GenerateCacheSnapshot(cacheIndex.Cache, cacheIndex.Timecodes, timecode.Value, cacheIndex.Asset.DurationInSeconds); if (cacheSnapshot.Count == 1) { cacheIndex.Timecodes.Remove(timecode.Value); double progress = cacheSnapshot.Keys.ElementAt(0); cacheIndex.Cache.Remove(progress); if (!updatedCache.ContainsKey(cacheIndexKey)) { updatedCache.Add(cacheIndexKey, cacheIndex); } } } } } } if (updatedCache.Count > 0) { foreach (string key in updatedCache.Keys) { CacheIndex cacheIndex = this.assetsCacheIndex[key]; IDictionary <double, double> newCache = GenerateCacheSnapshot(cacheIndex.Timecodes, cacheIndex.Asset.DurationInSeconds); cacheIndex.SetCache(newCache); this.OnCacheRebuilt(newCache, cacheIndex.Asset); } } }
/// <summary> /// 缓存表初始化 /// </summary> public void Init() { TableName = "客户端日志信息表"; CacheIndex uniqueIndex = new CacheIndex() { IndexName = IndexUnique, IndexType = IndexType.唯一索引, GetIndexKey = GetUniqueIndex }; AddIndex(uniqueIndex); }
protected static IntIntAlias Seek(CacheIndex cacheIndex, int value, int basic) { foreach (IntIntAlias alias in Cache[(int)cacheIndex]) { if (alias.value == value && alias.basic == basic) { return(alias); } } throw new GetDataException(cacheIndex.ToString()); }
protected static CharAlias Seek(CacheIndex cacheIndex, char value) { foreach (CharAlias alias in Cache[(int)cacheIndex]) { if (alias.value == value) { return(alias); } } throw new GetDataException(cacheIndex.ToString()); }
public async Task NonExpiredIndexReturnsCacheAsync() { var expected = 5; var username = "******"; var reponame = "repo"; var cache = new InMemoryBlobCache(); var apiClient = Substitute.For <IApiClient>(); var modelService = CreateTarget(apiClient: apiClient, hostCache: cache); var user = CreateOctokitUser(username); apiClient.GetUser().Returns(Observable.Return(user)); apiClient.GetOrganizations().Returns(Observable.Empty <Organization>()); var act = modelService.GetAccounts().ToEnumerable().First().First(); var repo = Substitute.For <LocalRepositoryModel>(); repo.Name.Returns(reponame); repo.CloneUrl.Returns(new UriString("https://github.com/" + username + "/" + reponame)); var indexKey = string.Format(CultureInfo.InvariantCulture, "{0}|{1}:{2}", CacheIndex.PRPrefix, user.Login, repo.Name); var prcache = Enumerable.Range(1, expected) .Select(id => CreatePullRequest(user, id, ItemState.Open, "Cache " + id, DateTimeOffset.UtcNow, DateTimeOffset.UtcNow)); // seed the cache prcache .Select(item => new PullRequestCacheItem(item)) .Select(item => item.Save <PullRequestCacheItem>(cache, indexKey).ToEnumerable().First()) .SelectMany(item => CacheIndex.AddAndSaveToIndex(cache, indexKey, item).ToEnumerable()) .ToList(); var prlive = Observable.Range(1, expected) .Select(id => CreatePullRequest(user, id, ItemState.Open, "Live " + id, DateTimeOffset.UtcNow, DateTimeOffset.UtcNow)) .DelaySubscription(TimeSpan.FromMilliseconds(10)); apiClient.GetPullRequestsForRepository(user.Login, repo.Name).Returns(prlive); await modelService.InsertUser(new AccountCacheItem(user)); ITrackingCollection <IPullRequestModel> col = new TrackingCollection <IPullRequestModel>(); modelService.GetPullRequests(repo, col); col.ProcessingDelay = TimeSpan.Zero; col.Subscribe(); await col.OriginalCompleted.Timeout(TimeSpan.FromMilliseconds(Timeout));; Assert.That(expected, Is.EqualTo(col.Count)); //Assert.Collection(col, col.Select(x => new Action<IPullRequestModel>(t => Assert.That("Cache", StartsWith(x.Title)))).ToArray()); }
public DocumentCache(CacheSettings settings) { Settings = settings; myCacheFolder = Path.Combine(Path.GetTempPath(), "Maui.Data.Recognition.Cache"); if (!Directory.Exists(myCacheFolder)) { Directory.CreateDirectory(myCacheFolder); } myIndexFile = Path.Combine(myCacheFolder, "cache.idx"); myIndex = CacheIndex.LoadOrCreate(myIndexFile); }
public DocumentCache( CacheSettings settings ) { Settings = settings; myCacheFolder = Path.Combine( Path.GetTempPath(), "Maui.Data.Recognition.Cache" ); if ( !Directory.Exists( myCacheFolder ) ) { Directory.CreateDirectory( myCacheFolder ); } myIndexFile = Path.Combine( myCacheFolder, "cache.idx" ); myIndex = CacheIndex.LoadOrCreate( myIndexFile ); }
protected void InitCache(Connection conn, CacheIndex cacheIndex) { SqlSelect select = new SqlSelect(Name, null); int index = (int)cacheIndex; if (Cache[index] != null) { throw new RangeException(String.Format("Caching index {0} twice", index)); } Cache[index] = new List <Alias>(); LoadArray(conn, select, Cache[index]); }
public override byte[] GetFileData(CacheIndex index, int fileId, CacheFileInfo?info) { // Read the sectors and take their payload data up to the size of the contained file. return(this .GetFileSectors(index, fileId, out var filesize) .Aggregate(new List <byte>(), (bytes, sector) => { bytes.AddRange(sector.Payload); return bytes; }) .Take(filesize) .ToArray()); }
public DocumentCache(CacheSettings settings) { Settings = settings; myCacheFolder = Path.Combine(Path.GetTempPath(), "RaynMaker.Modules.Import.Cache"); if (!Directory.Exists(myCacheFolder)) { Directory.CreateDirectory(myCacheFolder); } myIndexFile = Path.Combine(myCacheFolder, "cache.idx"); myIndex = CacheIndex.LoadOrCreate(myIndexFile); }
/// <summary> /// Updates the existing index item. /// </summary> /// <param name="clientIndex">Index from the client.</param> /// <param name="cacheIndexInternal">The cache index internal.</param> /// <param name="indexInfo">The index info.</param> /// <param name="addItem">The add item.</param> /// <param name="searchIndex">Index to search.</param> /// <param name="storeContext">The store context.</param> /// <param name="comparer">The comparer.</param> private static void UpdateExistingIndexItem(CacheIndex clientIndex, CacheIndexInternal cacheIndexInternal, Index indexInfo, IndexDataItem addItem, int searchIndex, IndexStoreContext storeContext, InternalItemComparer comparer) { InternalItem internalItem = cacheIndexInternal.InternalItemList[searchIndex]; if (clientIndex.TargetIndexName != null) //Save to single index { if (addItem.Tags != null && addItem.Tags.Count > 0) { bool reposition = IsRepositioningOfIndexItemRequired(indexInfo, addItem, internalItem); // Update all tags on the internal item foreach (KeyValuePair <string, byte[]> kvp in addItem.Tags) { storeContext.TagHashCollection.AddTag(cacheIndexInternal.InDeserializationContext.TypeId, kvp.Key); internalItem.UpdateTag(TagHashCollection.GetTagHashCode(kvp.Key), kvp.Value); } // Reposition index item if required if (reposition) { RepositionIndexItem(cacheIndexInternal, indexInfo, addItem, searchIndex, internalItem, comparer); } } } else //Save to multiple indexes { if (addItem.Tags != null && addItem.Tags.Count > 0) { List <string> tagNameList; byte[] tagValue; clientIndex.IndexTagMapping.TryGetValue(cacheIndexInternal.InDeserializationContext.IndexName, out tagNameList); bool reposition = IsRepositioningOfIndexItemRequired(indexInfo, addItem, internalItem); // Update all tags on the internal item foreach (string tagName in tagNameList) { //Add to tagHashCollection storeContext.TagHashCollection.AddTag(cacheIndexInternal.InDeserializationContext.TypeId, tagName); addItem.TryGetTagValue(tagName, out tagValue); internalItem.UpdateTag(TagHashCollection.GetTagHashCode(tagName), tagValue); } // Reposition index item if required if (reposition) { RepositionIndexItem(cacheIndexInternal, indexInfo, addItem, searchIndex, internalItem, comparer); } } } }
public void IsExpired_WhenNewXapFile_ReturnsTrue() { //Arrange var cacheIndex = new CacheIndex(); //Act //Assert Assert.IsTrue(cacheIndex.IsExpired(string.Empty, new Version(0, 0))); }
public void IsExpired_WhenOtherVersion_ReturnsTrue() { //Arrange var cacheIndex = new CacheIndex(); var xapName = Guid.NewGuid().ToString(); var version = new Version(1, 0); var otherVersion = new Version(1, 1); //Act cacheIndex.Add(xapName, version); //Assert Assert.IsTrue(cacheIndex.IsExpired(xapName, otherVersion)); }
public void Remove_WhenNewXapFile_ReturnsTrue() { //Arrange var cacheIndex = new CacheIndex(); var xapName = Guid.NewGuid().ToString(); var version = new Version(1, 0); //Act cacheIndex.Add(xapName, version); cacheIndex.Remove(xapName); //Assert Assert.IsTrue(cacheIndex.IsExpired(xapName, version)); }
public void Reset(CacheIndex.Item new_definition) { definition = new_definition; Database.SetRoot(definition); }