示例#1
0
        //Check compression
        public void QuantlerCompression_Compress_Succeeded()
        {
            //Arrange
            var inputdata = Encoding.ASCII.GetBytes(Input);

            //Act
            var result = Compress.CompressBytes(inputdata, "testing");

            //Assert
            result.Should().NotBeNull();
            result.Length.Should().BePositive();
            result.Length.Should().BeLessThan(inputdata.Length);
        }
示例#2
0
        //Check uncompress
        public void QuantlerCompression_Uncompress_Succeeded()
        {
            //Arrange
            var inputdata       = Encoding.ASCII.GetBytes(Input);
            var inputcompressed = Compress.CompressBytes(inputdata, "testing");

            //Act
            var decompressed = Compress.UncompressBytes(inputcompressed, "testing");
            var result       = Encoding.ASCII.GetString(decompressed);

            //Assert
            decompressed.Should().NotBeNull();
            result.Should().NotBeNullOrWhiteSpace();
            result.Should().Be(Input);
        }
示例#3
0
        /// <summary>
        /// Try and load data for date from cache
        /// http://www.alphadevx.com/a/387-Changing-the-maximum-item-size-allowed-by-Memcache
        /// </summary>
        /// <param name="sub"></param>
        /// <param name="date"></param>
        /// <returns></returns>
        private async Task <MemoryStream> LoadFromCacheAsync(DataSubscriptionRequest sub, DateTime date)
        {
            string key = DataPointCached.GetKey(sub.Ticker.Name, sub.DataType, sub.Aggregation, date);

            byte[] found = null;

            //Check if we are allowed to use cache
            if (_useCache)
            {
                //Try and load from cache
                var cacheitem = _cachedFiles.Get(key);
                if (cacheitem != null)
                {
                    return(new MemoryStream(Compress.UncompressBytes(cacheitem.Data, key)));
                }
            }

            //Fall back to disk if not present
            if (found == null)
            {
                var disk = await LoadFromDiskAsync(sub, date);

                if (disk != null && _useCache)
                {
                    //Create cache item, we store the result compressed in cache
                    var cacheitem = DataPointCached.Create(sub.Ticker.Name, sub.DataType, sub.Aggregation, date, Compress.CompressBytes(disk.ToArray(), key));
                    _cachedFiles.Put(key, cacheitem);
                }

                //Return disk data
                return(disk);
            }

            //This should not happen
            return(null);
        }