Post merge fix

This commit is contained in:
Bjarke Berg
2024-01-13 20:47:16 +01:00
parent aa6f704353
commit 9811eaebeb
5 changed files with 13 additions and 41 deletions

View File

@@ -19,6 +19,7 @@
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0" /> <PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" /> <PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0" /> <PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" /> <PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" /> <PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" /> <PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
@@ -32,7 +33,6 @@
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.0" /> <PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" /> <PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0" /> <PackageVersion Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0" />
<PackageVersion Include="System.Runtime.Caching" Version="8.0.0" />
</ItemGroup> </ItemGroup>
<!-- Umbraco packages --> <!-- Umbraco packages -->
<ItemGroup> <ItemGroup>

View File

@@ -65,15 +65,14 @@ public static class AppCacheExtensions
string cacheKey, string cacheKey,
Func<Task<T?>> getCacheItemAsync, Func<Task<T?>> getCacheItemAsync,
TimeSpan? timeout, TimeSpan? timeout,
bool isSliding = false, bool isSliding = false)
string[]? dependentFiles = null)
{ {
var result = provider.Get(cacheKey); var result = provider.Get(cacheKey);
if (result == null) if (result == null)
{ {
result = await getCacheItemAsync(); result = await getCacheItemAsync();
provider.Insert(cacheKey, () => result, timeout, isSliding, dependentFiles); provider.Insert(cacheKey, () => result, timeout, isSliding);
} }
return result == null ? default : result.TryConvertTo<T>().Result; return result == null ? default : result.TryConvertTo<T>().Result;
@@ -84,10 +83,9 @@ public static class AppCacheExtensions
string cacheKey, string cacheKey,
Func<Task<T>> getCacheItemAsync, Func<Task<T>> getCacheItemAsync,
TimeSpan? timeout = null, TimeSpan? timeout = null,
bool isSliding = false, bool isSliding = false)
string[]? dependentFiles = null)
{ {
T value = await getCacheItemAsync(); T value = await getCacheItemAsync();
provider.Insert(cacheKey, () => value, timeout, isSliding, dependentFiles); provider.Insert(cacheKey, () => value, timeout, isSliding);
} }
} }

View File

@@ -1,6 +1,5 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
@@ -106,7 +105,7 @@ public class ObjectCacheAppCache : IAppPolicyCache, IDisposable
} }
/// <inheritdoc /> /// <inheritdoc />
public object? Get(string key, Func<object?> factory, TimeSpan? timeout, bool isSliding = false, string[]? dependentFiles = null) public object? Get(string key, Func<object?> factory, TimeSpan? timeout, bool isSliding = false)
{ {
// see notes in HttpRuntimeAppCache // see notes in HttpRuntimeAppCache
Lazy<object?>? result; Lazy<object?>? result;
@@ -121,7 +120,7 @@ public class ObjectCacheAppCache : IAppPolicyCache, IDisposable
if (result == null || SafeLazy.GetSafeLazyValue(result, true) == null) if (result == null || SafeLazy.GetSafeLazyValue(result, true) == null)
{ {
result = SafeLazy.GetSafeLazy(factory); result = SafeLazy.GetSafeLazy(factory);
MemoryCacheEntryOptions options = GetOptions(timeout, isSliding, dependentFiles); MemoryCacheEntryOptions options = GetOptions(timeout, isSliding);
try try
{ {
@@ -159,7 +158,7 @@ public class ObjectCacheAppCache : IAppPolicyCache, IDisposable
} }
/// <inheritdoc /> /// <inheritdoc />
public void Insert(string key, Func<object?> factory, TimeSpan? timeout = null, bool isSliding = false, string[]? dependentFiles = null) public void Insert(string key, Func<object?> factory, TimeSpan? timeout = null, bool isSliding = false)
{ {
// NOTE - here also we must insert a Lazy<object> but we can evaluate it right now // NOTE - here also we must insert a Lazy<object> but we can evaluate it right now
// and make sure we don't store a null value. // and make sure we don't store a null value.
@@ -170,7 +169,7 @@ public class ObjectCacheAppCache : IAppPolicyCache, IDisposable
return; // do not store null values (backward compat) return; // do not store null values (backward compat)
} }
MemoryCacheEntryOptions options = GetOptions(timeout, isSliding, dependentFiles); MemoryCacheEntryOptions options = GetOptions(timeout, isSliding);
// NOTE: This does an add or update // NOTE: This does an add or update
MemoryCache.Set(key, result, options); MemoryCache.Set(key, result, options);
@@ -323,7 +322,7 @@ public class ObjectCacheAppCache : IAppPolicyCache, IDisposable
} }
} }
private MemoryCacheEntryOptions GetOptions(TimeSpan? timeout = null, bool isSliding = false, string[]? dependentFiles = null) private MemoryCacheEntryOptions GetOptions(TimeSpan? timeout = null, bool isSliding = false)
{ {
var options = new MemoryCacheEntryOptions(); var options = new MemoryCacheEntryOptions();
@@ -337,19 +336,6 @@ public class ObjectCacheAppCache : IAppPolicyCache, IDisposable
options.AbsoluteExpirationRelativeToNow = timeout; options.AbsoluteExpirationRelativeToNow = timeout;
} }
// Configure file based expiration
if (dependentFiles?.Length > 0 && _hostEnvironment?.ContentRootFileProvider is IFileProvider fileProvider)
{
foreach (var dependentFile in dependentFiles)
{
var relativePath = Path.IsPathFullyQualified(dependentFile)
? Path.GetRelativePath(_hostEnvironment.ContentRootPath, dependentFile)
: dependentFile;
options.ExpirationTokens.Add(fileProvider.Watch(relativePath));
}
}
// Ensure key is removed from set when evicted from cache // Ensure key is removed from set when evicted from cache
return options.RegisterPostEvictionCallback((key, _, _, _) => _keys.Remove((string)key)); return options.RegisterPostEvictionCallback((key, _, _, _) => _keys.Remove((string)key));
} }

View File

@@ -7,6 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Memory" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" /> <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" /> <PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" /> <PackageReference Include="Microsoft.Extensions.FileProviders.Physical" />
@@ -17,19 +18,6 @@
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" /> <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" /> <PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" />
<PackageReference Include="System.Runtime.Caching" /> <PackageReference Include="System.Runtime.Caching" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0-rc.2.*" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0-rc.2.*" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="8.0.0-rc.2.*" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="8.0.0-rc.2.*" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0-rc.2.*" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="8.0.0-rc.2.*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0-rc.2.*" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.0-rc.2.*" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0-rc.2.*" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0-rc.2.*" />
<PackageReference Include="System.Runtime.Caching" Version="8.0.0-rc.2.*" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -38,7 +38,7 @@ public class OpenIddictCleanupJob : IRecurringBackgroundJob
try try
{ {
IOpenIddictTokenManager tokenManager = scope.ServiceProvider.GetService<IOpenIddictTokenManager>() IOpenIddictTokenManager tokenManager = scope.ServiceProvider.GetService<IOpenIddictTokenManager>()
?? throw new ConfigurationErrorsException($"Could not retrieve an {nameof(IOpenIddictTokenManager)} service from the current scope"); ?? throw new InvalidOperationException($"Could not retrieve an {nameof(IOpenIddictTokenManager)} service from the current scope");
await tokenManager.PruneAsync(threshold); await tokenManager.PruneAsync(threshold);
} }
catch (Exception exception) catch (Exception exception)
@@ -49,7 +49,7 @@ public class OpenIddictCleanupJob : IRecurringBackgroundJob
try try
{ {
IOpenIddictAuthorizationManager authorizationManager = scope.ServiceProvider.GetService<IOpenIddictAuthorizationManager>() IOpenIddictAuthorizationManager authorizationManager = scope.ServiceProvider.GetService<IOpenIddictAuthorizationManager>()
?? throw new ConfigurationErrorsException($"Could not retrieve an {nameof(IOpenIddictAuthorizationManager)} service from the current scope"); ?? throw new InvalidOperationException($"Could not retrieve an {nameof(IOpenIddictAuthorizationManager)} service from the current scope");
await authorizationManager.PruneAsync(threshold); await authorizationManager.PruneAsync(threshold);
} }
catch (Exception exception) catch (Exception exception)