Skip to content

Commit

Permalink
Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
Codespilot committed Oct 8, 2024
1 parent 9304bae commit fe9fd40
Show file tree
Hide file tree
Showing 7 changed files with 524 additions and 509 deletions.
2 changes: 1 addition & 1 deletion Source/Euonia.Application/Behaviors/BearerTokenBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task<CommandResponse> HandleAsync(IRoutedMessage context, PipelineD
{
if (!string.IsNullOrWhiteSpace(value) && value.StartsWith("Bearer") && !value.Equals("Bearer null", StringComparison.OrdinalIgnoreCase))
{
context.Metadata.Set("$nerosoft:token", value);
context.Metadata.Set("Authorization", value);
}
}

Expand Down
3 changes: 3 additions & 0 deletions Source/Euonia.Application/Behaviors/UserPrincipalBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public async Task<CommandResponse> HandleAsync(IRoutedMessage context, PipelineD
context.Metadata.Set("$nerosoft:user.tenant", _user.Tenant);
}

{
}

return await next(context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static IServiceCollection AddApplicationService(this IServiceCollection s
/// <param name="services">The <see cref="IServiceCollection"/> instance of current application.</param>
/// <param name="definedTypes">The application service types.</param>
/// <returns></returns>
/// <remarks>The application service type should inherits from <see cref="IApplicationService"/>.</remarks>
/// <remarks>The application service type should inherit from <see cref="IApplicationService"/>.</remarks>
public static IServiceCollection AddApplicationService(this IServiceCollection services, IEnumerable<Type> definedTypes)
{
if (!definedTypes.Any())
Expand Down
2 changes: 1 addition & 1 deletion Source/Euonia.Business/Factory/ObjectReflector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ private static Tuple<Type, bool> FindServiceType(string name, Type type, bool? m
throw new NotSupportedException($"Can not inject property '{name}', the property type {type.FullName} is not supported.");
}

var @interface = type.GetInterface("IEnumerable");
var @interface = type.GetInterface(nameof(IEnumerable));
if (@interface == null)
{
return Tuple.Create(type, multiple ?? false);
Expand Down
74 changes: 43 additions & 31 deletions Source/Euonia.Caching.Memory/MemoryCacheExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,47 @@ namespace Nerosoft.Euonia.Caching.Memory;
/// </summary>
internal static class MemoryCacheExtensions
{
/// <summary>
/// Extension method to check if a key exists in the given <paramref name="cache"/> instance.
/// </summary>
/// <param name="cache">The cache instance.</param>
/// <param name="key">The key.</param>
/// <returns><c>True</c> if the key exists.</returns>
public static bool Contains(this MemoryCache cache, object key)
{
return cache.TryGetValue(key, out _);
}

internal static void RegisterChild(this MemoryCache cache, object parentKey, object childKey)
{
if (cache.TryGetValue(parentKey, out var keys))
{
var keySet = (ConcurrentDictionary<object, bool>)keys;
keySet.TryAdd(childKey, true);
}
}

internal static void RemoveChilds(this MemoryCache cache, object region)
{
if (cache.TryGetValue(region, out var keys))
{
var keySet = (ConcurrentDictionary<object, bool>)keys;
foreach (var key in keySet.Keys)
{
cache.Remove(key);
}
}
}
/// <summary>
/// Extension method to check if a key exists in the given <paramref name="cache"/> instance.
/// </summary>
/// <param name="cache">The cache instance.</param>
/// <param name="key">The key.</param>
/// <returns><c>True</c> if the key exists.</returns>
public static bool Contains(this IMemoryCache cache, object key)
{
return cache.TryGetValue(key, out _);
}

internal static void RegisterChild(this IMemoryCache cache, object parentKey, object childKey)
{
if (!cache.TryGetValue(parentKey, out var keys))
{
return;
}

if (keys is not ConcurrentDictionary<object, bool> keySet)
{
throw new InvalidOperationException("The parent key is not a valid key set.");
}

keySet.TryAdd(childKey, true);
}

internal static void RemoveChildren(this IMemoryCache cache, object region)
{
if (!cache.TryGetValue(region, out var keys))
{
return;
}

if (keys is not ConcurrentDictionary<object, bool> keySet)
{
return;
}

foreach (var key in keySet.Keys)
{
cache.Remove(key);
}
}
}
2 changes: 1 addition & 1 deletion Source/Euonia.Caching.Memory/MemoryCacheHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override void Clear()
/// <inheritdoc/>
public override void ClearRegion(string region)
{
_cache.RemoveChilds(region);
_cache.RemoveChildren(region);
_cache.Remove(region);
}

Expand Down
Loading

0 comments on commit fe9fd40

Please sign in to comment.