mirror of https://github.com/abpframework/abp.git
committed by
GitHub
26 changed files with 199 additions and 141 deletions
@ -1,8 +1,9 @@ |
|||
using System.Threading.Tasks; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.Web.Configuration; |
|||
|
|||
public interface ICurrentApplicationConfigurationCacheResetService |
|||
{ |
|||
Task ResetAsync(); |
|||
Task ResetAsync(Guid? userId = null); |
|||
} |
|||
|
|||
@ -1,13 +1,26 @@ |
|||
using System.Globalization; |
|||
using Volo.Abp.Users; |
|||
using System; |
|||
using System.Globalization; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.Client; |
|||
|
|||
public static class MvcCachedApplicationConfigurationClientHelper |
|||
public class MvcCachedApplicationConfigurationClientHelper : ITransientDependency |
|||
{ |
|||
public static string CreateCacheKey(ICurrentUser currentUser) |
|||
protected IDistributedCache<MvcCachedApplicationVersionCacheItem> ApplicationVersionCache { get; } |
|||
|
|||
public MvcCachedApplicationConfigurationClientHelper(IDistributedCache<MvcCachedApplicationVersionCacheItem> applicationVersionCache) |
|||
{ |
|||
ApplicationVersionCache = applicationVersionCache; |
|||
} |
|||
|
|||
public virtual async Task<string> CreateCacheKeyAsync(Guid? userId) |
|||
{ |
|||
var userKey = currentUser.Id?.ToString("N") ?? "Anonymous"; |
|||
return $"ApplicationConfiguration_{userKey}_{CultureInfo.CurrentUICulture.Name}"; |
|||
var appVersion = await ApplicationVersionCache.GetOrAddAsync(MvcCachedApplicationVersionCacheItem.CacheKey, |
|||
() => Task.FromResult(new MvcCachedApplicationVersionCacheItem(Guid.NewGuid().ToString("N")))) ?? |
|||
new MvcCachedApplicationVersionCacheItem(Guid.NewGuid().ToString("N")); |
|||
var userKey = userId?.ToString("N") ?? "Anonymous"; |
|||
return $"ApplicationConfiguration_{appVersion.Version}_{userKey}_{CultureInfo.CurrentUICulture.Name}"; |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,13 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.Client; |
|||
|
|||
public class MvcCachedApplicationVersionCacheItem |
|||
{ |
|||
public const string CacheKey = "Mvc_Application_Version"; |
|||
|
|||
public string Version { get; set; } |
|||
|
|||
public MvcCachedApplicationVersionCacheItem(string version) |
|||
{ |
|||
Version = version; |
|||
} |
|||
} |
|||
@ -1,9 +1,21 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; |
|||
using System; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; |
|||
|
|||
/// <summary>
|
|||
/// This event is used to invalidate current user's cached configuration.
|
|||
/// </summary>
|
|||
public class CurrentApplicationConfigurationCacheResetEventData |
|||
{ |
|||
public Guid? UserId { get; set; } |
|||
|
|||
public CurrentApplicationConfigurationCacheResetEventData() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public CurrentApplicationConfigurationCacheResetEventData(Guid? userId) |
|||
{ |
|||
UserId = userId; |
|||
} |
|||
} |
|||
|
|||
@ -1,20 +1,21 @@ |
|||
using System; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.DistributedLocking; |
|||
|
|||
public class LocalAbpDistributedLockHandle : IAbpDistributedLockHandle |
|||
namespace Volo.Abp.DistributedLocking |
|||
{ |
|||
private readonly IDisposable _disposable; |
|||
|
|||
public LocalAbpDistributedLockHandle(IDisposable disposable) |
|||
public class LocalAbpDistributedLockHandle : IAbpDistributedLockHandle |
|||
{ |
|||
_disposable = disposable; |
|||
} |
|||
private readonly SemaphoreSlim _semaphore; |
|||
|
|||
public ValueTask DisposeAsync() |
|||
{ |
|||
_disposable.Dispose(); |
|||
return default; |
|||
public LocalAbpDistributedLockHandle(SemaphoreSlim semaphore) |
|||
{ |
|||
_semaphore = semaphore; |
|||
} |
|||
|
|||
public ValueTask DisposeAsync() |
|||
{ |
|||
_semaphore.Release(); |
|||
return default; |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,32 @@ |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.EventBus; |
|||
using Volo.Abp.StaticDefinitions; |
|||
using Volo.Abp.TextTemplating; |
|||
using Volo.Abp.Threading; |
|||
|
|||
namespace Volo.Abp.TextTemplateManagement; |
|||
|
|||
public class StaticTemplateDefinitionChangedEventHandler : ILocalEventHandler<StaticTemplateDefinitionChangedEvent>, ITransientDependency |
|||
{ |
|||
protected IStaticDefinitionCache<TemplateDefinition, Dictionary<string, TemplateDefinition>> DefinitionCache { get; } |
|||
protected TextTemplateDynamicInitializer TextTemplateDynamicInitializer { get; } |
|||
protected ICancellationTokenProvider CancellationTokenProvider { get; } |
|||
|
|||
public StaticTemplateDefinitionChangedEventHandler( |
|||
IStaticDefinitionCache<TemplateDefinition, Dictionary<string, TemplateDefinition>> definitionCache, |
|||
TextTemplateDynamicInitializer textTemplateDynamicInitializer, |
|||
ICancellationTokenProvider cancellationTokenProvider) |
|||
{ |
|||
DefinitionCache = definitionCache; |
|||
TextTemplateDynamicInitializer = textTemplateDynamicInitializer; |
|||
CancellationTokenProvider = cancellationTokenProvider; |
|||
} |
|||
|
|||
public virtual async Task HandleEventAsync(StaticTemplateDefinitionChangedEvent eventData) |
|||
{ |
|||
await DefinitionCache.ClearAsync(); |
|||
await TextTemplateDynamicInitializer.InitializeAsync(false, CancellationTokenProvider.Token); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue