Browse Source
Merge pull request #1774 from abpframework/maliming/cacheKeyPrefix
Add application name prefix option to distributed cache item keys.
pull/1775/head
Halil İbrahim Kalkan
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with
55 additions and
1 deletions
-
framework/src/Volo.Abp.Caching/Volo/Abp/Caching/CacheOptions.cs
-
framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs
-
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs
-
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs
-
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs
-
templates/module/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs
-
templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs
-
templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebHostModule.cs
|
|
|
@ -6,6 +6,11 @@ namespace Volo.Abp.Caching |
|
|
|
{ |
|
|
|
public class CacheOptions |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Cache key prefix.
|
|
|
|
/// </summary>
|
|
|
|
public string KeyPrefix { get; set; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Global Cache entry options.
|
|
|
|
/// </summary>
|
|
|
|
@ -21,6 +26,7 @@ namespace Volo.Abp.Caching |
|
|
|
{ |
|
|
|
CacheConfigurators = new List<Func<string, DistributedCacheEntryOptions>>(); |
|
|
|
GlobalCacheEntryOptions = new DistributedCacheEntryOptions(); |
|
|
|
KeyPrefix = ""; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -405,7 +405,7 @@ namespace Volo.Abp.Caching |
|
|
|
|
|
|
|
protected virtual string NormalizeKey(string key) |
|
|
|
{ |
|
|
|
var normalizedKey = "c:" + CacheName + ",k:" + key; |
|
|
|
var normalizedKey = "c:" + CacheName + ",k:" + _cacheOption.KeyPrefix + key; |
|
|
|
|
|
|
|
if (!IgnoreMultiTenancy && CurrentTenant.Id.HasValue) |
|
|
|
{ |
|
|
|
|
|
|
|
@ -15,6 +15,7 @@ using Volo.Abp; |
|
|
|
using Volo.Abp.AspNetCore.MultiTenancy; |
|
|
|
using Volo.Abp.AspNetCore.Mvc; |
|
|
|
using Volo.Abp.Autofac; |
|
|
|
using Volo.Abp.Caching; |
|
|
|
using Volo.Abp.Localization; |
|
|
|
using Volo.Abp.Modularity; |
|
|
|
using Volo.Abp.VirtualFileSystem; |
|
|
|
@ -41,11 +42,20 @@ namespace MyCompanyName.MyProjectName |
|
|
|
ConfigureAuthentication(context, configuration); |
|
|
|
ConfigureSwagger(context); |
|
|
|
ConfigureLocalization(); |
|
|
|
ConfigureCache(configuration); |
|
|
|
ConfigureVirtualFileSystem(context); |
|
|
|
ConfigureRedis(context, configuration, hostingEnvironment); |
|
|
|
ConfigureCors(context, configuration); |
|
|
|
} |
|
|
|
|
|
|
|
private void ConfigureCache(IConfigurationRoot configuration) |
|
|
|
{ |
|
|
|
Configure<CacheOptions>(options => |
|
|
|
{ |
|
|
|
options.KeyPrefix = "MyProjectName:"; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private void ConfigureVirtualFileSystem(ServiceConfigurationContext context) |
|
|
|
{ |
|
|
|
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
|
|
|
|
|
|
|
@ -20,6 +20,7 @@ using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; |
|
|
|
using Volo.Abp.Auditing; |
|
|
|
using Volo.Abp.Autofac; |
|
|
|
using Volo.Abp.BackgroundJobs; |
|
|
|
using Volo.Abp.Caching; |
|
|
|
using Volo.Abp.Localization; |
|
|
|
using Volo.Abp.Modularity; |
|
|
|
using Volo.Abp.UI.Navigation.Urls; |
|
|
|
@ -91,6 +92,11 @@ namespace MyCompanyName.MyProjectName |
|
|
|
options.IsJobExecutionEnabled = false; |
|
|
|
}); |
|
|
|
|
|
|
|
Configure<CacheOptions>(options => |
|
|
|
{ |
|
|
|
options.KeyPrefix = "MyProjectName:"; |
|
|
|
}); |
|
|
|
|
|
|
|
context.Services.AddStackExchangeRedisCache(options => |
|
|
|
{ |
|
|
|
options.Configuration = configuration["Redis:Configuration"]; |
|
|
|
|
|
|
|
@ -22,6 +22,7 @@ using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; |
|
|
|
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; |
|
|
|
using Volo.Abp.Autofac; |
|
|
|
using Volo.Abp.AutoMapper; |
|
|
|
using Volo.Abp.Caching; |
|
|
|
using Volo.Abp.FeatureManagement; |
|
|
|
using Volo.Abp.Http.Client.IdentityModel; |
|
|
|
using Volo.Abp.Identity.Web; |
|
|
|
@ -68,6 +69,7 @@ namespace MyCompanyName.MyProjectName.Web |
|
|
|
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
|
|
|
var configuration = context.Services.GetConfiguration(); |
|
|
|
|
|
|
|
ConfigureCache(configuration); |
|
|
|
ConfigureUrls(configuration); |
|
|
|
ConfigureAuthentication(context, configuration); |
|
|
|
ConfigureAutoMapper(); |
|
|
|
@ -77,6 +79,14 @@ namespace MyCompanyName.MyProjectName.Web |
|
|
|
ConfigureMultiTenancy(); |
|
|
|
} |
|
|
|
|
|
|
|
private void ConfigureCache(IConfigurationRoot configuration) |
|
|
|
{ |
|
|
|
Configure<CacheOptions>(options => |
|
|
|
{ |
|
|
|
options.KeyPrefix = "MyProjectName:"; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private void ConfigureUrls(IConfigurationRoot configuration) |
|
|
|
{ |
|
|
|
Configure<AppUrlOptions>(options => |
|
|
|
|
|
|
|
@ -11,6 +11,7 @@ using Volo.Abp; |
|
|
|
using Volo.Abp.AspNetCore.MultiTenancy; |
|
|
|
using Volo.Abp.AuditLogging.EntityFrameworkCore; |
|
|
|
using Volo.Abp.Autofac; |
|
|
|
using Volo.Abp.Caching; |
|
|
|
using Volo.Abp.EntityFrameworkCore; |
|
|
|
using Volo.Abp.EntityFrameworkCore.SqlServer; |
|
|
|
using Volo.Abp.Localization; |
|
|
|
@ -86,6 +87,11 @@ namespace MyCompanyName.MyProjectName |
|
|
|
options.ApiName = "MyProjectName"; |
|
|
|
}); |
|
|
|
|
|
|
|
Configure<CacheOptions>(options => |
|
|
|
{ |
|
|
|
options.KeyPrefix = "MyProjectName:"; |
|
|
|
}); |
|
|
|
|
|
|
|
context.Services.AddStackExchangeRedisCache(options => |
|
|
|
{ |
|
|
|
options.Configuration = configuration["Redis:Configuration"]; |
|
|
|
|
|
|
|
@ -14,6 +14,7 @@ using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; |
|
|
|
using Volo.Abp.Auditing; |
|
|
|
using Volo.Abp.AuditLogging.EntityFrameworkCore; |
|
|
|
using Volo.Abp.Autofac; |
|
|
|
using Volo.Abp.Caching; |
|
|
|
using Volo.Abp.Data; |
|
|
|
using Volo.Abp.EntityFrameworkCore; |
|
|
|
using Volo.Abp.EntityFrameworkCore.SqlServer; |
|
|
|
@ -105,6 +106,11 @@ namespace MyCompanyName.MyProjectName |
|
|
|
options.ApiName = configuration["AuthServer:ApiName"]; |
|
|
|
}); |
|
|
|
|
|
|
|
Configure<CacheOptions>(options => |
|
|
|
{ |
|
|
|
options.KeyPrefix = "MyProjectName:"; |
|
|
|
}); |
|
|
|
|
|
|
|
context.Services.AddStackExchangeRedisCache(options => |
|
|
|
{ |
|
|
|
options.Configuration = configuration["Redis:Configuration"]; |
|
|
|
|
|
|
|
@ -22,6 +22,7 @@ using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; |
|
|
|
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; |
|
|
|
using Volo.Abp.Autofac; |
|
|
|
using Volo.Abp.AutoMapper; |
|
|
|
using Volo.Abp.Caching; |
|
|
|
using Volo.Abp.Http.Client.IdentityModel; |
|
|
|
using Volo.Abp.Identity; |
|
|
|
using Volo.Abp.Identity.Web; |
|
|
|
@ -72,6 +73,7 @@ namespace MyCompanyName.MyProjectName |
|
|
|
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
|
|
|
var configuration = context.Services.GetConfiguration(); |
|
|
|
|
|
|
|
ConfigureCache(configuration); |
|
|
|
ConfigureUrls(configuration); |
|
|
|
ConfigureAuthentication(context, configuration); |
|
|
|
ConfigureAutoMapper(); |
|
|
|
@ -80,6 +82,14 @@ namespace MyCompanyName.MyProjectName |
|
|
|
ConfigureMultiTenancy(); |
|
|
|
ConfigureRedis(context, configuration, hostingEnvironment); |
|
|
|
} |
|
|
|
|
|
|
|
private void ConfigureCache(IConfigurationRoot configuration) |
|
|
|
{ |
|
|
|
Configure<CacheOptions>(options => |
|
|
|
{ |
|
|
|
options.KeyPrefix = "MyProjectName:"; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private void ConfigureUrls(IConfigurationRoot configuration) |
|
|
|
{ |
|
|
|
|