mirror of https://github.com/abpframework/abp.git
13 changed files with 106 additions and 40 deletions
@ -1,8 +1,9 @@ |
|||||
using System.Threading.Tasks; |
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.Web.Configuration; |
namespace Volo.Abp.AspNetCore.Components.Web.Configuration; |
||||
|
|
||||
public interface ICurrentApplicationConfigurationCacheResetService |
public interface ICurrentApplicationConfigurationCacheResetService |
||||
{ |
{ |
||||
Task ResetAsync(); |
Task ResetAsync(Guid? userId = null); |
||||
} |
} |
||||
|
|||||
@ -1,13 +1,26 @@ |
|||||
using System.Globalization; |
using System; |
||||
using Volo.Abp.Users; |
using System.Globalization; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Caching; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Mvc.Client; |
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"; |
var appVersion = await ApplicationVersionCache.GetOrAddAsync(MvcCachedApplicationVersionCacheItem.CacheKey, |
||||
return $"ApplicationConfiguration_{userKey}_{CultureInfo.CurrentUICulture.Name}"; |
() => Task.FromResult(new MvcCachedApplicationVersionCacheItem(Guid.NewGuid().ToString()))) ?? |
||||
|
new MvcCachedApplicationVersionCacheItem(Guid.NewGuid().ToString()); |
||||
|
var userKey = userId?.ToString("N") ?? "Anonymous"; |
||||
|
return $"ApplicationConfiguration_{appVersion}_{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>
|
/// <summary>
|
||||
/// This event is used to invalidate current user's cached configuration.
|
/// This event is used to invalidate current user's cached configuration.
|
||||
/// </summary>
|
/// </summary>
|
||||
public class CurrentApplicationConfigurationCacheResetEventData |
public class CurrentApplicationConfigurationCacheResetEventData |
||||
{ |
{ |
||||
|
public Guid? UserId { get; set; } |
||||
|
|
||||
|
public CurrentApplicationConfigurationCacheResetEventData() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public CurrentApplicationConfigurationCacheResetEventData(Guid? userId) |
||||
|
{ |
||||
|
UserId = userId; |
||||
|
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue