< Summary

Information
Class: Services.FidSupplierLinkServices.FidSuppliersFeedCache
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/FidSupplierLinkServices/FidSuppliersFeedCache.cs
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 44
Line coverage: 100%
Branch coverage
85%
Covered branches: 17
Total branches: 20
Branch coverage: 85%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetAsync()85%2020100%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/FidSupplierLinkServices/FidSuppliersFeedCache.cs

#LineLine coverage
 1using Microsoft.Extensions.Caching.Memory;
 2using Services.ApiServices.FidApi;
 3using Services.ApiServices.FidApi.Models;
 4using Services.SystemMonitoringServices;
 5
 6namespace Services.FidSupplierLinkServices;
 7
 8public sealed class FidSuppliersFeedCache
 9{
 10    private const string CacheKey = "fid_suppliers_v1";
 11    private readonly IMemoryCache _cache;
 12    private readonly FidApiDataManager _fid;
 13    private readonly ISystemMonitoringSignalWriter? _signals;
 14
 3415    public FidSuppliersFeedCache(IMemoryCache cache, FidApiDataManager fid, ISystemMonitoringSignalWriter? signals = nul
 16    {
 3417        _cache = cache;
 3418        _fid = fid;
 3419        _signals = signals;
 3420    }
 21
 22    public async Task<(FidSuppliers? Feed, string? Error)> GetAsync(bool forceRefresh = false, CancellationToken ct = de
 23    {
 1724        if (!forceRefresh && _cache.TryGetValue(CacheKey, out FidSuppliers? cached) && cached is not null)
 125            return (cached, null);
 26        try
 27        {
 1628            var feed = await _fid.GetSuppliersAsync(includeDisabled: true, ct);
 1429            if (feed is null)
 30            {
 131                await (_signals?.RecordAsync("fid-suppliers-load", "failure", message: "Фид-сервис не вернул список пост
 132                return (null, "Фид-сервис не вернул список поставщиков.");
 33            }
 1334            _cache.Set(CacheKey, feed, TimeSpan.FromMinutes(5));
 1335            await (_signals?.RecordAsync("fid-suppliers-load", "success", cancellationToken: ct) ?? Task.CompletedTask);
 1336            return (feed, null);
 37        }
 38        catch (Exception ex)
 39        {
 240            await (_signals?.RecordAsync("fid-suppliers-load", "failure", message: "Фид-сервис недоступен", cancellation
 241            return (null, $"Фид-сервис недоступен: {ex.Message}");
 42        }
 1743    }
 44}