< Summary

Information
Class: MyNet.Utilities.Caching.CacheStorageValueInfo<T>
Assembly: MyNet.Utilities
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Utilities/Caching/CacheStorageValueInfo.cs
Tag: 323_28699572109
Line coverage
45%
Covered lines: 5
Uncovered lines: 6
Coverable lines: 11
Total lines: 90
Line coverage: 45.4%
Branch coverage
58%
Covered branches: 7
Total branches: 12
Branch coverage: 58.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
get_Value()66.66%7666.66%
get_CanExpire()100%11100%
get_IsExpired()75%44100%
.ctor(...)100%11100%
DisposeValue()0%620%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Utilities/Caching/CacheStorageValueInfo.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="CacheStorageValueInfo.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using MyNet.Utilities.Caching.Policies;
 9
 10namespace MyNet.Utilities.Caching;
 11
 12/// <summary>
 13/// Value info for the cache storage.
 14/// </summary>
 15/// <typeparam name="TValue">
 16/// The value type.
 17/// </typeparam>
 18/// <remarks>
 19/// Initializes a new instance of the <see cref="CacheStorageValueInfo{TValue}" /> class.
 20/// </remarks>
 21/// <param name="value">The value.</param>
 22/// <param name="expirationPolicy">The expiration policy.</param>
 23internal sealed class CacheStorageValueInfo<TValue>(TValue value, ExpirationPolicy? expirationPolicy = null)
 24{
 25    #region Constructors
 26
 27    /// <summary>
 28    /// Initializes a new instance of the <see cref="CacheStorageValueInfo{TValue}" /> class.
 29    /// </summary>
 30    /// <param name="value">The value.</param>
 31    /// <param name="expiration">The expiration.</param>
 32    public CacheStorageValueInfo(TValue value, TimeSpan expiration)
 033        : this(value, ExpirationPolicy.Duration(expiration))
 34    {
 035    }
 36
 37    #endregion
 38
 39    #region Properties
 40
 41    /// <summary>
 42    /// Gets the value.
 43    /// </summary>
 44    /// <value>The value.</value>
 45    public TValue Value
 46    {
 47        get
 48        {
 2149            if (CanExpire && (ExpirationPolicy?.CanReset ?? false))
 50            {
 051                ExpirationPolicy.Reset();
 52            }
 53
 2154            return value;
 55        }
 56    }
 57
 58    /// <summary>
 59    /// Gets a value indicating whether this value can expire.
 60    /// </summary>
 61    /// <value><c>true</c> if this value can expire; otherwise, <c>false</c>.</value>
 4862    public bool CanExpire => ExpirationPolicy is not null;
 63
 64    /// <summary>
 65    /// Gets a value indicating whether this value is expired.
 66    /// </summary>
 67    /// <value><c>true</c> if this value is expired; otherwise, <c>false</c>.</value>
 1568    public bool IsExpired => CanExpire && (ExpirationPolicy?.IsExpired ?? false);
 69
 70    /// <summary>
 71    /// Gets the expiration policy.
 72    /// </summary>
 1273    internal ExpirationPolicy? ExpirationPolicy { get; } = expirationPolicy;
 74
 75    #endregion
 76
 77    #region Methods
 78
 79    /// <summary>
 80    /// Dispose value.
 81    /// </summary>
 82    public void DisposeValue()
 83    {
 084        var disposable = value as IDisposable;
 085        disposable?.Dispose();
 086    }
 87
 88    #endregion
 89}
 90