Ejemplo n.º 1
0
        private async Task <ChannelItemResult> GetAllItems(IIndexableChannel indexable, IChannel channel, string userId, CancellationToken cancellationToken)
        {
            var cacheLength = TimeSpan.FromHours(12);
            var cachePath   = GetChannelDataCachePath(channel, userId, "channelmanager-allitems", null, false);

            try
            {
                if (_fileSystem.GetLastWriteTimeUtc(cachePath).Add(cacheLength) > DateTime.UtcNow)
                {
                    return(_jsonSerializer.DeserializeFromFile <ChannelItemResult>(cachePath));
                }
            }
            catch (FileNotFoundException)
            {
            }
            catch (DirectoryNotFoundException)
            {
            }

            await _resourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);

            try
            {
                try
                {
                    if (_fileSystem.GetLastWriteTimeUtc(cachePath).Add(cacheLength) > DateTime.UtcNow)
                    {
                        return(_jsonSerializer.DeserializeFromFile <ChannelItemResult>(cachePath));
                    }
                }
                catch (FileNotFoundException)
                {
                }
                catch (DirectoryNotFoundException)
                {
                }

                var result = await indexable.GetAllMedia(new InternalAllChannelMediaQuery
                {
                    UserId = userId
                }, cancellationToken).ConfigureAwait(false);

                CacheResponse(result, cachePath);

                return(result);
            }
            finally
            {
                _resourcePool.Release();
            }
        }
Ejemplo n.º 2
0
        private async Task<ChannelItemResult> GetAllItems(IIndexableChannel indexable, IChannel channel, string userId, CancellationToken cancellationToken)
        {
            var cacheLength = TimeSpan.FromHours(12);
            var cachePath = GetChannelDataCachePath(channel, userId, "channelmanager-allitems", null, false);

            try
            {
                if (_fileSystem.GetLastWriteTimeUtc(cachePath).Add(cacheLength) > DateTime.UtcNow)
                {
                    return _jsonSerializer.DeserializeFromFile<ChannelItemResult>(cachePath);
                }
            }
            catch (FileNotFoundException)
            {

            }
            catch (DirectoryNotFoundException)
            {

            }

            await _resourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);

            try
            {
                try
                {
                    if (_fileSystem.GetLastWriteTimeUtc(cachePath).Add(cacheLength) > DateTime.UtcNow)
                    {
                        return _jsonSerializer.DeserializeFromFile<ChannelItemResult>(cachePath);
                    }
                }
                catch (FileNotFoundException)
                {

                }
                catch (DirectoryNotFoundException)
                {

                }

                var result = await indexable.GetAllMedia(new InternalAllChannelMediaQuery
                {
                    UserId = userId

                }, cancellationToken).ConfigureAwait(false);

                CacheResponse(result, cachePath);

                return result;
            }
            finally
            {
                _resourcePool.Release();
            }
        }