Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HybridCache: reflect API merge into runtime #56945

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Caching/Hybrid/src/Internal/DefaultHybridCache.L2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,19 @@ private DistributedCacheEntryOptions GetOptions(HybridCacheEntryOptions? options
DistributedCacheEntryOptions? result = null;
if (options is not null && options.Expiration.HasValue && options.Expiration.GetValueOrDefault() != _defaultExpiration)
{
result = options.ToDistributedCacheEntryOptions();
result = ToDistributedCacheEntryOptions(options);
}
return result ?? _defaultDistributedCacheExpiration;

#if NET8_0_OR_GREATER
// internal method memoizes this allocation; since it is "init", it is immutable (outside reflection)
[UnsafeAccessor(UnsafeAccessorKind.Method, Name = nameof(ToDistributedCacheEntryOptions))]
extern static DistributedCacheEntryOptions? ToDistributedCacheEntryOptions(HybridCacheEntryOptions options);
#else
// withoug that helper method, we'll just eat the alloc (down-level TFMs)
static DistributedCacheEntryOptions ToDistributedCacheEntryOptions(HybridCacheEntryOptions options)
=> new() { AbsoluteExpirationRelativeToNow = options.Expiration };
#endif
}

internal void SetL1<T>(string key, CacheItem<T> value, HybridCacheEntryOptions? options)
Expand Down
10 changes: 5 additions & 5 deletions src/Caching/Hybrid/src/Internal/DefaultHybridCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
/// <summary>
/// The inbuilt ASP.NET implementation of <see cref="HybridCache"/>.
/// </summary>
internal sealed partial class DefaultHybridCache : HybridCache

Check failure on line 22 in src/Caching/Hybrid/src/Internal/DefaultHybridCache.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: Ubuntu x64)

src/Caching/Hybrid/src/Internal/DefaultHybridCache.cs#L22

src/Caching/Hybrid/src/Internal/DefaultHybridCache.cs(22,52): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HybridCache' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 22 in src/Caching/Hybrid/src/Internal/DefaultHybridCache.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: macOS)

src/Caching/Hybrid/src/Internal/DefaultHybridCache.cs#L22

src/Caching/Hybrid/src/Internal/DefaultHybridCache.cs(22,52): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HybridCache' could not be found (are you missing a using directive or an assembly reference?)
{
private readonly IDistributedCache? _backendCache;
private readonly IMemoryCache _localCache;
private readonly IServiceProvider _services; // we can't resolve per-type serializers until we see each T
private readonly IHybridCacheSerializerFactory[] _serializerFactories;

Check failure on line 27 in src/Caching/Hybrid/src/Internal/DefaultHybridCache.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: macOS)

src/Caching/Hybrid/src/Internal/DefaultHybridCache.cs#L27

src/Caching/Hybrid/src/Internal/DefaultHybridCache.cs(27,22): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'IHybridCacheSerializerFactory' could not be found (are you missing a using directive or an assembly reference?)
private readonly HybridCacheOptions _options;
private readonly ILogger _logger;
private readonly CacheFeatures _features; // used to avoid constant type-testing
Expand Down Expand Up @@ -108,12 +108,12 @@
private HybridCacheEntryFlags GetEffectiveFlags(HybridCacheEntryOptions? options)
=> (options?.Flags | _hardFlags) ?? _defaultFlags;

public override ValueTask<T> GetOrCreateAsync<TState, T>(string key, TState state, Func<TState, CancellationToken, ValueTask<T>> underlyingDataCallback, HybridCacheEntryOptions? options = null, IReadOnlyCollection<string>? tags = null, CancellationToken token = default)
public override ValueTask<T> GetOrCreateAsync<TState, T>(string key, TState state, Func<TState, CancellationToken, ValueTask<T>> underlyingDataCallback, HybridCacheEntryOptions? options = null, IEnumerable<string>? tags = null, CancellationToken cancellationToken = default)
{
var canBeCanceled = token.CanBeCanceled;
var canBeCanceled = cancellationToken.CanBeCanceled;
if (canBeCanceled)
{
token.ThrowIfCancellationRequested();
cancellationToken.ThrowIfCancellationRequested();
}

var flags = GetEffectiveFlags(options);
Expand Down Expand Up @@ -141,7 +141,7 @@
}
}

return stampede.JoinAsync(token);
return stampede.JoinAsync(cancellationToken);
}

public override ValueTask RemoveAsync(string key, CancellationToken token = default)
Expand All @@ -153,7 +153,7 @@
public override ValueTask RemoveByTagAsync(string tag, CancellationToken token = default)
=> default; // tags not yet implemented

public override ValueTask SetAsync<T>(string key, T value, HybridCacheEntryOptions? options = null, IReadOnlyCollection<string>? tags = null, CancellationToken token = default)
public override ValueTask SetAsync<T>(string key, T value, HybridCacheEntryOptions? options = null, IEnumerable<string>? tags = null, CancellationToken token = default)
{
// since we're forcing a write: disable L1+L2 read; we'll use a direct pass-thru of the value as the callback, to reuse all the code;
// note also that stampede token is not shared with anyone else
Expand Down
51 changes: 0 additions & 51 deletions src/Caching/Hybrid/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,53 +1,4 @@
#nullable enable
abstract Microsoft.Extensions.Caching.Hybrid.HybridCache.GetOrCreateAsync<TState, T>(string! key, TState state, System.Func<TState, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<T>>! factory, Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryOptions? options = null, System.Collections.Generic.IReadOnlyCollection<string!>? tags = null, System.Threading.CancellationToken token = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<T>
abstract Microsoft.Extensions.Caching.Hybrid.HybridCache.RemoveAsync(string! key, System.Threading.CancellationToken token = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
abstract Microsoft.Extensions.Caching.Hybrid.HybridCache.RemoveByTagAsync(string! tag, System.Threading.CancellationToken token = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
abstract Microsoft.Extensions.Caching.Hybrid.HybridCache.SetAsync<T>(string! key, T value, Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryOptions? options = null, System.Collections.Generic.IReadOnlyCollection<string!>? tags = null, System.Threading.CancellationToken token = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
Microsoft.Extensions.Caching.Distributed.IBufferDistributedCache
Microsoft.Extensions.Caching.Distributed.IBufferDistributedCache.Set(string! key, System.Buffers.ReadOnlySequence<byte> value, Microsoft.Extensions.Caching.Distributed.DistributedCacheEntryOptions! options) -> void
Microsoft.Extensions.Caching.Distributed.IBufferDistributedCache.SetAsync(string! key, System.Buffers.ReadOnlySequence<byte> value, Microsoft.Extensions.Caching.Distributed.DistributedCacheEntryOptions! options, System.Threading.CancellationToken token = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
Microsoft.Extensions.Caching.Distributed.IBufferDistributedCache.TryGet(string! key, System.Buffers.IBufferWriter<byte>! destination) -> bool
Microsoft.Extensions.Caching.Distributed.IBufferDistributedCache.TryGetAsync(string! key, System.Buffers.IBufferWriter<byte>! destination, System.Threading.CancellationToken token = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<bool>
Microsoft.Extensions.Caching.Hybrid.HybridCache
Microsoft.Extensions.Caching.Hybrid.HybridCache.GetOrCreateAsync<T>(string! key, System.Func<System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<T>>! factory, Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryOptions? options = null, System.Collections.Generic.IReadOnlyCollection<string!>? tags = null, System.Threading.CancellationToken token = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask<T>
Microsoft.Extensions.Caching.Hybrid.HybridCache.HybridCache() -> void
Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags
Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags.DisableCompression = 32 -> Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags
Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags.DisableDistributedCache = Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags.DisableDistributedCacheRead | Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags.DisableDistributedCacheWrite -> Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags
Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags.DisableDistributedCacheRead = 4 -> Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags
Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags.DisableDistributedCacheWrite = 8 -> Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags
Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags.DisableLocalCache = Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags.DisableLocalCacheRead | Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags.DisableLocalCacheWrite -> Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags
Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags.DisableLocalCacheRead = 1 -> Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags
Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags.DisableLocalCacheWrite = 2 -> Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags
Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags.DisableUnderlyingData = 16 -> Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags
Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags.None = 0 -> Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags
Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryOptions
Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryOptions.Expiration.get -> System.TimeSpan?
Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryOptions.Expiration.init -> void
Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryOptions.Flags.get -> Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryFlags?
Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryOptions.Flags.init -> void
Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryOptions.HybridCacheEntryOptions() -> void
Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryOptions.LocalCacheExpiration.get -> System.TimeSpan?
Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryOptions.LocalCacheExpiration.init -> void
Microsoft.Extensions.Caching.Hybrid.HybridCacheOptions
Microsoft.Extensions.Caching.Hybrid.HybridCacheOptions.DefaultEntryOptions.get -> Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryOptions?
Microsoft.Extensions.Caching.Hybrid.HybridCacheOptions.DefaultEntryOptions.set -> void
Microsoft.Extensions.Caching.Hybrid.HybridCacheOptions.DisableCompression.get -> bool
Microsoft.Extensions.Caching.Hybrid.HybridCacheOptions.DisableCompression.set -> void
Microsoft.Extensions.Caching.Hybrid.HybridCacheOptions.HybridCacheOptions() -> void
Microsoft.Extensions.Caching.Hybrid.HybridCacheOptions.MaximumKeyLength.get -> int
Microsoft.Extensions.Caching.Hybrid.HybridCacheOptions.MaximumKeyLength.set -> void
Microsoft.Extensions.Caching.Hybrid.HybridCacheOptions.MaximumPayloadBytes.get -> long
Microsoft.Extensions.Caching.Hybrid.HybridCacheOptions.MaximumPayloadBytes.set -> void
Microsoft.Extensions.Caching.Hybrid.HybridCacheOptions.ReportTagMetrics.get -> bool
Microsoft.Extensions.Caching.Hybrid.HybridCacheOptions.ReportTagMetrics.set -> void
Microsoft.Extensions.Caching.Hybrid.IHybridCacheBuilder
Microsoft.Extensions.Caching.Hybrid.IHybridCacheBuilder.Services.get -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
Microsoft.Extensions.Caching.Hybrid.IHybridCacheSerializer<T>
Microsoft.Extensions.Caching.Hybrid.IHybridCacheSerializer<T>.Deserialize(System.Buffers.ReadOnlySequence<byte> source) -> T
Microsoft.Extensions.Caching.Hybrid.IHybridCacheSerializer<T>.Serialize(T value, System.Buffers.IBufferWriter<byte>! target) -> void
Microsoft.Extensions.Caching.Hybrid.IHybridCacheSerializerFactory
Microsoft.Extensions.Caching.Hybrid.IHybridCacheSerializerFactory.TryCreateSerializer<T>(out Microsoft.Extensions.Caching.Hybrid.IHybridCacheSerializer<T>? serializer) -> bool
Microsoft.Extensions.DependencyInjection.HybridCacheBuilderExtensions
Microsoft.Extensions.DependencyInjection.HybridCacheServiceExtensions
static Microsoft.Extensions.DependencyInjection.HybridCacheBuilderExtensions.AddSerializer<T, TImplementation>(this Microsoft.Extensions.Caching.Hybrid.IHybridCacheBuilder! builder) -> Microsoft.Extensions.Caching.Hybrid.IHybridCacheBuilder!
Expand All @@ -56,5 +7,3 @@ static Microsoft.Extensions.DependencyInjection.HybridCacheBuilderExtensions.Add
static Microsoft.Extensions.DependencyInjection.HybridCacheBuilderExtensions.AddSerializerFactory<TImplementation>(this Microsoft.Extensions.Caching.Hybrid.IHybridCacheBuilder! builder) -> Microsoft.Extensions.Caching.Hybrid.IHybridCacheBuilder!
static Microsoft.Extensions.DependencyInjection.HybridCacheServiceExtensions.AddHybridCache(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.Caching.Hybrid.IHybridCacheBuilder!
static Microsoft.Extensions.DependencyInjection.HybridCacheServiceExtensions.AddHybridCache(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action<Microsoft.Extensions.Caching.Hybrid.HybridCacheOptions!>! setupAction) -> Microsoft.Extensions.Caching.Hybrid.IHybridCacheBuilder!
virtual Microsoft.Extensions.Caching.Hybrid.HybridCache.RemoveAsync(System.Collections.Generic.IEnumerable<string!>! keys, System.Threading.CancellationToken token = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
virtual Microsoft.Extensions.Caching.Hybrid.HybridCache.RemoveByTagAsync(System.Collections.Generic.IEnumerable<string!>! tags, System.Threading.CancellationToken token = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask
Loading
Loading