BTDB.ChunkCache.DiskChunkCache.CalcStats C# (CSharp) Method

CalcStats() public method

public CalcStats ( ) : string
return string
        public string CalcStats()
        {
            var res = new StringBuilder();
            res.AppendFormat("Files {0} FileInfos {1} FileGeneration {2} Cached items {3}{4}", _fileCollection.GetCount(),
                             _fileInfos.Count, _fileGeneration, _cache.Count, Environment.NewLine);
            var totalSize = 0UL;
            var totalControledSize = 0UL;
            foreach (var fileCollectionFile in _fileCollection.Enumerate())
            {
                IFileInfo fileInfo;
                _fileInfos.TryGetValue(fileCollectionFile.Index, out fileInfo);
                var size = fileCollectionFile.GetSize();
                totalSize += size;
                if (fileInfo == null)
                {
                    res.AppendFormat("{0} Size: {1} Unknown to cache{2}", fileCollectionFile.Index,
                                     size, Environment.NewLine);
                }
                else
                {
                    res.AppendFormat("{0} Size: {1} Type: {2} {3}", fileCollectionFile.Index,
                                     size, fileInfo.FileType, Environment.NewLine);
                    totalControledSize += size;
                }
            }
            res.AppendFormat("TotalSize {0} TotalControledSize {1} Limit {2}{3}", totalSize, totalControledSize,
                             _cacheCapacity, Environment.NewLine);
            Debug.Assert(totalControledSize <= (ulong)_cacheCapacity);
            return res.ToString();
        }

Usage Example

Example #1
0
 public void GettingContentMakesItStayLongerDecreasingRate()
 {
     using (var fileCollection = new InMemoryFileCollection())
     {
         const int cacheCapacity = 50000;
         using (var cache = new DiskChunkCache(fileCollection, 20, cacheCapacity))
         {
             for (var i = 0; i < 80; i++)
             {
                 Put(cache, i);
                 for (var j = 0; j < 79 - i; j++)
                     Get(cache, i);
                 Assert.LessOrEqual(fileCollection.Enumerate().Sum(f => (long)f.GetSize()), cacheCapacity);
             }
             Console.WriteLine(cache.CalcStats());
             Assert.True(Get(cache, 0));
             Assert.False(Get(cache, 60));
         }
     }
 }
All Usage Examples Of BTDB.ChunkCache.DiskChunkCache::CalcStats