Browse Source

Backport the caching changes to OpenIddict 1.x

pull/670/head
Kévin Chalet 9 years ago
parent
commit
e0d65df51a
  1. 42
      src/OpenIddict.Core/Stores/OpenIddictApplicationStore.cs
  2. 14
      src/OpenIddict.Core/Stores/OpenIddictScopeStore.cs
  3. 31
      src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs
  4. 41
      src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs
  5. 27
      src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs
  6. 41
      src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs
  7. 12
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs
  8. 41
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs
  9. 13
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs
  10. 41
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs

42
src/OpenIddict.Core/Stores/OpenIddictApplicationStore.cs

@ -390,15 +390,17 @@ namespace OpenIddict.Core
// To mitigate that, the resulting array is stored in the memory cache. // To mitigate that, the resulting array is stored in the memory cache.
var key = string.Concat(nameof(GetPermissionsAsync), "\x1e", application.Permissions); var key = string.Concat(nameof(GetPermissionsAsync), "\x1e", application.Permissions);
var permissions = Cache.Get(key) as ImmutableArray<string>?; var permissions = Cache.GetOrCreate(key, entry =>
if (permissions == null)
{ {
permissions = Cache.Set(key, JArray.Parse(application.Permissions) entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JArray.Parse(application.Permissions)
.Select(element => (string) element) .Select(element => (string) element)
.ToImmutableArray()); .ToImmutableArray();
} });
return new ValueTask<ImmutableArray<string>>(permissions.GetValueOrDefault()); return new ValueTask<ImmutableArray<string>>(permissions);
} }
/// <summary> /// <summary>
@ -426,15 +428,17 @@ namespace OpenIddict.Core
// To mitigate that, the resulting array is stored in the memory cache. // To mitigate that, the resulting array is stored in the memory cache.
var key = string.Concat(nameof(GetPostLogoutRedirectUrisAsync), "\x1e", application.PostLogoutRedirectUris); var key = string.Concat(nameof(GetPostLogoutRedirectUrisAsync), "\x1e", application.PostLogoutRedirectUris);
var addresses = Cache.Get(key) as ImmutableArray<string>?; var addresses = Cache.GetOrCreate(key, entry =>
if (addresses == null)
{ {
addresses = Cache.Set(key, JArray.Parse(application.PostLogoutRedirectUris) entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JArray.Parse(application.PostLogoutRedirectUris)
.Select(element => (string) element) .Select(element => (string) element)
.ToImmutableArray()); .ToImmutableArray();
} });
return new ValueTask<ImmutableArray<string>>(addresses.GetValueOrDefault()); return new ValueTask<ImmutableArray<string>>(addresses);
} }
/// <summary> /// <summary>
@ -486,15 +490,17 @@ namespace OpenIddict.Core
// To mitigate that, the resulting array is stored in the memory cache. // To mitigate that, the resulting array is stored in the memory cache.
var key = string.Concat(nameof(GetRedirectUrisAsync), "\x1e", application.RedirectUris); var key = string.Concat(nameof(GetRedirectUrisAsync), "\x1e", application.RedirectUris);
var addresses = Cache.Get(key) as ImmutableArray<string>?; var addresses = Cache.GetOrCreate(key, entry =>
if (addresses == null)
{ {
addresses = Cache.Set(key, JArray.Parse(application.RedirectUris) entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JArray.Parse(application.RedirectUris)
.Select(element => (string) element) .Select(element => (string) element)
.ToImmutableArray()); .ToImmutableArray();
} });
return new ValueTask<ImmutableArray<string>>(addresses.GetValueOrDefault()); return new ValueTask<ImmutableArray<string>>(addresses);
} }
/// <summary> /// <summary>

14
src/OpenIddict.Core/Stores/OpenIddictScopeStore.cs

@ -303,15 +303,17 @@ namespace OpenIddict.Core
// To mitigate that, the resulting array is stored in the memory cache. // To mitigate that, the resulting array is stored in the memory cache.
var key = string.Concat(nameof(GetResourcesAsync), "\x1e", scope.Resources); var key = string.Concat(nameof(GetResourcesAsync), "\x1e", scope.Resources);
var resources = Cache.Get(key) as ImmutableArray<string>?; var resources = Cache.GetOrCreate(key, entry =>
if (resources == null)
{ {
resources = Cache.Set(key, JArray.Parse(scope.Resources) entry.SetPriority(CacheItemPriority.High)
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JArray.Parse(scope.Resources)
.Select(element => (string) element) .Select(element => (string) element)
.ToImmutableArray()); .ToImmutableArray();
} });
return new ValueTask<ImmutableArray<string>>(resources.GetValueOrDefault()); return new ValueTask<ImmutableArray<string>>(resources);
} }
/// <summary> /// <summary>

31
src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs

@ -29,9 +29,7 @@ namespace OpenIddict.EntityFramework
OpenIddictToken, TContext, string> OpenIddictToken, TContext, string>
where TContext : DbContext where TContext : DbContext
{ {
public OpenIddictApplicationStore( public OpenIddictApplicationStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(context, cache) : base(context, cache)
{ {
} }
@ -49,9 +47,7 @@ namespace OpenIddict.EntityFramework
where TContext : DbContext where TContext : DbContext
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
public OpenIddictApplicationStore( public OpenIddictApplicationStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(context, cache) : base(context, cache)
{ {
} }
@ -74,9 +70,7 @@ namespace OpenIddict.EntityFramework
where TContext : DbContext where TContext : DbContext
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
public OpenIddictApplicationStore( public OpenIddictApplicationStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(cache) : base(cache)
{ {
if (context == null) if (context == null)
@ -216,25 +210,6 @@ namespace OpenIddict.EntityFramework
} }
} }
/// <summary>
/// Retrieves an application using its unique identifier.
/// </summary>
/// <param name="identifier">The unique identifier associated with the application.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the client application corresponding to the identifier.
/// </returns>
public override Task<TApplication> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier));
}
return Applications.FindAsync(cancellationToken, ConvertIdentifierFromString(identifier));
}
/// <summary> /// <summary>
/// Executes the specified query and returns the first element. /// Executes the specified query and returns the first element.
/// </summary> /// </summary>

41
src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs

@ -29,9 +29,7 @@ namespace OpenIddict.EntityFramework
OpenIddictToken, TContext, string> OpenIddictToken, TContext, string>
where TContext : DbContext where TContext : DbContext
{ {
public OpenIddictAuthorizationStore( public OpenIddictAuthorizationStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(context, cache) : base(context, cache)
{ {
} }
@ -49,9 +47,7 @@ namespace OpenIddict.EntityFramework
where TContext : DbContext where TContext : DbContext
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
public OpenIddictAuthorizationStore( public OpenIddictAuthorizationStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(context, cache) : base(context, cache)
{ {
} }
@ -74,9 +70,7 @@ namespace OpenIddict.EntityFramework
where TContext : DbContext where TContext : DbContext
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
public OpenIddictAuthorizationStore( public OpenIddictAuthorizationStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(cache) : base(cache)
{ {
if (context == null) if (context == null)
@ -198,35 +192,6 @@ namespace OpenIddict.EntityFramework
} }
} }
/// <summary>
/// Retrieves an authorization using its unique identifier.
/// </summary>
/// <param name="identifier">The unique identifier associated with the authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the authorization corresponding to the identifier.
/// </returns>
public override Task<TAuthorization> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier));
}
var authorization = (from entry in Context.ChangeTracker.Entries<TAuthorization>()
where entry.Entity != null
where entry.Entity.Id.Equals(ConvertIdentifierFromString(identifier))
select entry.Entity).FirstOrDefault();
if (authorization != null)
{
return Task.FromResult(authorization);
}
return base.FindByIdAsync(identifier, cancellationToken);
}
/// <summary> /// <summary>
/// Retrieves the optional application identifier associated with an authorization. /// Retrieves the optional application identifier associated with an authorization.
/// </summary> /// </summary>

27
src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs

@ -43,9 +43,7 @@ namespace OpenIddict.EntityFramework
where TContext : DbContext where TContext : DbContext
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
public OpenIddictScopeStore( public OpenIddictScopeStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(context, cache) : base(context, cache)
{ {
} }
@ -63,9 +61,7 @@ namespace OpenIddict.EntityFramework
where TContext : DbContext where TContext : DbContext
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
public OpenIddictScopeStore( public OpenIddictScopeStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(cache) : base(cache)
{ {
if (context == null) if (context == null)
@ -146,25 +142,6 @@ namespace OpenIddict.EntityFramework
return Context.SaveChangesAsync(cancellationToken); return Context.SaveChangesAsync(cancellationToken);
} }
/// <summary>
/// Retrieves a scope using its unique identifier.
/// </summary>
/// <param name="identifier">The unique identifier associated with the scope.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the scope corresponding to the identifier.
/// </returns>
public override Task<TScope> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier));
}
return Scopes.FindAsync(cancellationToken, ConvertIdentifierFromString(identifier));
}
/// <summary> /// <summary>
/// Executes the specified query and returns the first element. /// Executes the specified query and returns the first element.
/// </summary> /// </summary>

41
src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs

@ -29,9 +29,7 @@ namespace OpenIddict.EntityFramework
OpenIddictAuthorization, TContext, string> OpenIddictAuthorization, TContext, string>
where TContext : DbContext where TContext : DbContext
{ {
public OpenIddictTokenStore( public OpenIddictTokenStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(context, cache) : base(context, cache)
{ {
} }
@ -49,9 +47,7 @@ namespace OpenIddict.EntityFramework
where TContext : DbContext where TContext : DbContext
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
public OpenIddictTokenStore( public OpenIddictTokenStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(context, cache) : base(context, cache)
{ {
} }
@ -74,9 +70,7 @@ namespace OpenIddict.EntityFramework
where TContext : DbContext where TContext : DbContext
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
public OpenIddictTokenStore( public OpenIddictTokenStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(cache) : base(cache)
{ {
if (context == null) if (context == null)
@ -165,35 +159,6 @@ namespace OpenIddict.EntityFramework
return Context.SaveChangesAsync(cancellationToken); return Context.SaveChangesAsync(cancellationToken);
} }
/// <summary>
/// Retrieves a token using its unique identifier.
/// </summary>
/// <param name="identifier">The unique identifier associated with the token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the token corresponding to the unique identifier.
/// </returns>
public override Task<TToken> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier));
}
var token = (from entry in Context.ChangeTracker.Entries<TToken>()
where entry.Entity != null
where entry.Entity.Id.Equals(ConvertIdentifierFromString(identifier))
select entry.Entity).FirstOrDefault();
if (token != null)
{
return Task.FromResult(token);
}
return base.FindByIdAsync(identifier, cancellationToken);
}
/// <summary> /// <summary>
/// Retrieves the optional application identifier associated with a token. /// Retrieves the optional application identifier associated with a token.
/// </summary> /// </summary>

12
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs

@ -31,9 +31,7 @@ namespace OpenIddict.EntityFrameworkCore
OpenIddictToken, TContext, string> OpenIddictToken, TContext, string>
where TContext : DbContext where TContext : DbContext
{ {
public OpenIddictApplicationStore( public OpenIddictApplicationStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(context, cache) : base(context, cache)
{ {
} }
@ -51,9 +49,7 @@ namespace OpenIddict.EntityFrameworkCore
where TContext : DbContext where TContext : DbContext
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
public OpenIddictApplicationStore( public OpenIddictApplicationStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(context, cache) : base(context, cache)
{ {
} }
@ -76,9 +72,7 @@ namespace OpenIddict.EntityFrameworkCore
where TContext : DbContext where TContext : DbContext
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
public OpenIddictApplicationStore( public OpenIddictApplicationStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(cache) : base(cache)
{ {
if (context == null) if (context == null)

41
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs

@ -31,9 +31,7 @@ namespace OpenIddict.EntityFrameworkCore
OpenIddictToken, TContext, string> OpenIddictToken, TContext, string>
where TContext : DbContext where TContext : DbContext
{ {
public OpenIddictAuthorizationStore( public OpenIddictAuthorizationStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(context, cache) : base(context, cache)
{ {
} }
@ -51,9 +49,7 @@ namespace OpenIddict.EntityFrameworkCore
where TContext : DbContext where TContext : DbContext
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
public OpenIddictAuthorizationStore( public OpenIddictAuthorizationStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(context, cache) : base(context, cache)
{ {
} }
@ -76,9 +72,7 @@ namespace OpenIddict.EntityFrameworkCore
where TContext : DbContext where TContext : DbContext
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
public OpenIddictAuthorizationStore( public OpenIddictAuthorizationStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(cache) : base(cache)
{ {
if (context == null) if (context == null)
@ -359,35 +353,6 @@ namespace OpenIddict.EntityFrameworkCore
Authorizations, Applications, ConvertIdentifierFromString(client), subject, status, type).ToListAsync(cancellationToken)); Authorizations, Applications, ConvertIdentifierFromString(client), subject, status, type).ToListAsync(cancellationToken));
} }
/// <summary>
/// Retrieves an authorization using its unique identifier.
/// </summary>
/// <param name="identifier">The unique identifier associated with the authorization.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the authorization corresponding to the identifier.
/// </returns>
public override Task<TAuthorization> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier));
}
var authorization = (from entry in Context.ChangeTracker.Entries<TAuthorization>()
where entry.Entity != null &&
entry.Entity.Id.Equals(ConvertIdentifierFromString(identifier))
select entry.Entity).FirstOrDefault();
if (authorization != null)
{
return Task.FromResult(authorization);
}
return base.FindByIdAsync(identifier, cancellationToken);
}
/// <summary> /// <summary>
/// Executes the specified query and returns the first element. /// Executes the specified query and returns the first element.
/// </summary> /// </summary>

13
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs

@ -12,7 +12,6 @@ using System.Threading.Tasks;
using JetBrains.Annotations; using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Caching.Memory;
using OpenIddict.Core;
using OpenIddict.Models; using OpenIddict.Models;
namespace OpenIddict.EntityFrameworkCore namespace OpenIddict.EntityFrameworkCore
@ -25,9 +24,7 @@ namespace OpenIddict.EntityFrameworkCore
public class OpenIddictScopeStore<TContext> : OpenIddictScopeStore<OpenIddictScope, TContext, string> public class OpenIddictScopeStore<TContext> : OpenIddictScopeStore<OpenIddictScope, TContext, string>
where TContext : DbContext where TContext : DbContext
{ {
public OpenIddictScopeStore( public OpenIddictScopeStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(context, cache) : base(context, cache)
{ {
} }
@ -43,9 +40,7 @@ namespace OpenIddict.EntityFrameworkCore
where TContext : DbContext where TContext : DbContext
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
public OpenIddictScopeStore( public OpenIddictScopeStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(context, cache) : base(context, cache)
{ {
} }
@ -63,9 +58,7 @@ namespace OpenIddict.EntityFrameworkCore
where TContext : DbContext where TContext : DbContext
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
public OpenIddictScopeStore( public OpenIddictScopeStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(cache) : base(cache)
{ {
if (context == null) if (context == null)

41
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs

@ -31,9 +31,7 @@ namespace OpenIddict.EntityFrameworkCore
OpenIddictAuthorization, TContext, string> OpenIddictAuthorization, TContext, string>
where TContext : DbContext where TContext : DbContext
{ {
public OpenIddictTokenStore( public OpenIddictTokenStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(context, cache) : base(context, cache)
{ {
} }
@ -51,9 +49,7 @@ namespace OpenIddict.EntityFrameworkCore
where TContext : DbContext where TContext : DbContext
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
public OpenIddictTokenStore( public OpenIddictTokenStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(context, cache) : base(context, cache)
{ {
} }
@ -76,9 +72,7 @@ namespace OpenIddict.EntityFrameworkCore
where TContext : DbContext where TContext : DbContext
where TKey : IEquatable<TKey> where TKey : IEquatable<TKey>
{ {
public OpenIddictTokenStore( public OpenIddictTokenStore([NotNull] TContext context, [NotNull] IMemoryCache cache)
[NotNull] TContext context,
[NotNull] IMemoryCache cache)
: base(cache) : base(cache)
{ {
if (context == null) if (context == null)
@ -229,35 +223,6 @@ namespace OpenIddict.EntityFrameworkCore
Authorizations, Tokens, ConvertIdentifierFromString(identifier)).ToListAsync(cancellationToken)); Authorizations, Tokens, ConvertIdentifierFromString(identifier)).ToListAsync(cancellationToken));
} }
/// <summary>
/// Retrieves a token using its unique identifier.
/// </summary>
/// <param name="identifier">The unique identifier associated with the token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the token corresponding to the unique identifier.
/// </returns>
public override Task<TToken> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier));
}
var token = (from entry in Context.ChangeTracker.Entries<TToken>()
where entry.Entity != null &&
entry.Entity.Id.Equals(ConvertIdentifierFromString(identifier))
select entry.Entity).FirstOrDefault();
if (token != null)
{
return Task.FromResult(token);
}
return base.FindByIdAsync(identifier, cancellationToken);
}
/// <summary> /// <summary>
/// Executes the specified query and returns the first element. /// Executes the specified query and returns the first element.
/// </summary> /// </summary>

Loading…
Cancel
Save