Exemple #1
0
        private async Task <CacheResult> GetValueOrDefault(DateTime key, bool forceRefresh)
        {
            if (_memoryCache.TryGetValue(key, out CacheResult result))
            {
                return(result);
            }

            var timeout   = _appSettingsConfig.CacheMonitorTimeout;
            var lockTaken = false;

            try
            {
                Monitor.TryEnter(_cacheLock, timeout, ref lockTaken);
                if (lockTaken)
                {
                    if (!forceRefresh && _memoryCache.TryGetValue(key, out result))
                    {
                        return(result);
                    }

                    result = _cachePackageBuilder.BuildPackage(key);

                    //If FUNC returns a null value, cache it for the defined amount of time
                    if (result == null)
                    {
                        //writes the Null placeholder object to the cache.
                        return(default);
Exemple #2
0
        public void BuildPackage_GiveTodaysDate_ShouldBuildCorrectPackage()
        {
            //Arrange
            //Test1
            ConstructPackageBuilderService(new AppSettingsConfig()
            {
                MaxKeysPerFile = 2
            });
            //Act
            var actualPackage = _packageBuilderService.BuildPackage(_today);

            //Assert
            Assert.That(actualPackage, Is.Not.Null);
            Assert.That(actualPackage.FileBytesList, Is.Not.Null);
            Assert.That(actualPackage.FileBytesList, Is.Not.Empty);
            Assert.That(actualPackage.FinalForTheDay, Is.EqualTo(false));
            Assert.That(actualPackage.NewerFilesExist, Is.EqualTo(false));
        }