diff --git a/.github/workflows/nuget-package-template.yml b/.github/workflows/nuget-package-template.yml index aecca1d..ce55d04 100644 --- a/.github/workflows/nuget-package-template.yml +++ b/.github/workflows/nuget-package-template.yml @@ -100,3 +100,23 @@ jobs: dotnet build -c Release dotnet pack -c Release -p:PackageVersion=${{ env.NEW_VERSION }} --output . dotnet nuget push "*.nupkg" --api-key ${{ secrets.GITHUB_TOKEN }} --source https://nuget.pkg.github.com/DFE-Digital/index.json + + - name: Get Release Description + id: extract_description + run: | + DESCRIPTION=$(git log -1 --pretty=format:"%s" | grep -oP '\(#description:.*\)' | sed 's/#description: //') + if [[ -z "$DESCRIPTION" ]]; then + DESCRIPTION="No release notes provided." + fi + echo "RELEASE_DESCRIPTION=$DESCRIPTION" >> $GITHUB_ENV + + - name: Create GitHub Release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ env.NEW_VERSION }} + release_name: Release ${{ env.NEW_VERSION }} + body: ${{ env.RELEASE_DESCRIPTION }} + draft: false + prerelease: false \ No newline at end of file diff --git a/src/DfE.CoreLibs.Caching/Interfaces/ICacheService.cs b/src/DfE.CoreLibs.Caching/Interfaces/ICacheService.cs index 58a5020..e4ad242 100644 --- a/src/DfE.CoreLibs.Caching/Interfaces/ICacheService.cs +++ b/src/DfE.CoreLibs.Caching/Interfaces/ICacheService.cs @@ -1,8 +1,9 @@ namespace DfE.CoreLibs.Caching.Interfaces { - public interface ICacheService + public interface ICacheService where TCacheType : ICacheType { Task GetOrAddAsync(string cacheKey, Func> fetchFunction, string methodName); void Remove(string cacheKey); + Type CacheType { get; } } } diff --git a/src/DfE.CoreLibs.Caching/Interfaces/ICacheType.cs b/src/DfE.CoreLibs.Caching/Interfaces/ICacheType.cs new file mode 100644 index 0000000..9700f11 --- /dev/null +++ b/src/DfE.CoreLibs.Caching/Interfaces/ICacheType.cs @@ -0,0 +1,4 @@ +namespace DfE.CoreLibs.Caching.Interfaces +{ + public interface ICacheType; +} diff --git a/src/DfE.CoreLibs.Caching/Interfaces/IMemoryCacheType.cs b/src/DfE.CoreLibs.Caching/Interfaces/IMemoryCacheType.cs new file mode 100644 index 0000000..31723bf --- /dev/null +++ b/src/DfE.CoreLibs.Caching/Interfaces/IMemoryCacheType.cs @@ -0,0 +1,4 @@ +namespace DfE.CoreLibs.Caching.Interfaces +{ + public interface IMemoryCacheType : ICacheType; +} diff --git a/src/DfE.CoreLibs.Caching/ServiceCollectionExtensions.cs b/src/DfE.CoreLibs.Caching/ServiceCollectionExtensions.cs index c688d21..7bf7eb4 100644 --- a/src/DfE.CoreLibs.Caching/ServiceCollectionExtensions.cs +++ b/src/DfE.CoreLibs.Caching/ServiceCollectionExtensions.cs @@ -11,7 +11,7 @@ public static IServiceCollection AddServiceCaching( this IServiceCollection services, IConfiguration config) { services.Configure(config.GetSection("CacheSettings")); - services.AddSingleton(); + services.AddSingleton, MemoryCacheService>(); return services; } diff --git a/src/DfE.CoreLibs.Caching/Services/MemoryCacheService.cs b/src/DfE.CoreLibs.Caching/Services/MemoryCacheService.cs index ef5c343..fc1be16 100644 --- a/src/DfE.CoreLibs.Caching/Services/MemoryCacheService.cs +++ b/src/DfE.CoreLibs.Caching/Services/MemoryCacheService.cs @@ -1,9 +1,9 @@ -using System.Diagnostics.CodeAnalysis; using DfE.CoreLibs.Caching.Interfaces; using DfE.CoreLibs.Caching.Settings; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using System.Diagnostics.CodeAnalysis; namespace DfE.CoreLibs.Caching.Services { @@ -12,9 +12,10 @@ public class MemoryCacheService( IMemoryCache memoryCache, ILogger logger, IOptions cacheSettings) - : ICacheService + : ICacheService { - private readonly CacheSettings _cacheSettings = cacheSettings.Value; + private readonly MemoryCacheSettings _cacheSettings = cacheSettings.Value.Memory; + public Type CacheType => typeof(IMemoryCacheType); public async Task GetOrAddAsync(string cacheKey, Func> fetchFunction, string methodName) { diff --git a/src/DfE.CoreLibs.Caching/Settings/CacheSettings.cs b/src/DfE.CoreLibs.Caching/Settings/CacheSettings.cs index a0acb3e..85cf1e7 100644 --- a/src/DfE.CoreLibs.Caching/Settings/CacheSettings.cs +++ b/src/DfE.CoreLibs.Caching/Settings/CacheSettings.cs @@ -1,6 +1,11 @@ namespace DfE.CoreLibs.Caching.Settings { public class CacheSettings + { + public MemoryCacheSettings Memory { get; set; } = new(); + } + + public class MemoryCacheSettings { public int DefaultDurationInSeconds { get; set; } = 5; public Dictionary Durations { get; set; } = new();