Browse Source

Merge pull request #959 from abpframework/cache-json-serializer

Introduce IDistributedCacheSerializer and implement as Utf8JsonDistributedCacheSerializer
pull/965/head
Halil İbrahim Kalkan 8 years ago
committed by GitHub
parent
commit
fde21a655d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Account.cshtml
  2. 4
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Application.cshtml
  3. 4
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Empty.cshtml
  4. 1
      framework/src/Volo.Abp.Caching/Volo.Abp.Caching.csproj
  5. 9
      framework/src/Volo.Abp.Caching/Volo/Abp/Caching/AbpCachingModule.cs
  6. 22
      framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs
  7. 9
      framework/src/Volo.Abp.Caching/Volo/Abp/Caching/IDistributedCacheSerializer.cs
  8. 26
      framework/src/Volo.Abp.Caching/Volo/Abp/Caching/Utf8JsonDistributedCacheSerializer.cs
  9. 4
      framework/src/Volo.Abp.Core/Volo.Abp.Core.csproj
  10. 4
      framework/test/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo/Pages/_Layout.cshtml
  11. 22
      modules/account/src/Volo.Abp.Account.Web.IdentityServer/AbpAccountWebIdentityServerModule.cs
  12. 2
      modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs

4
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Account.cshtml

@ -33,7 +33,7 @@
<abp-style-bundle name="@BasicThemeBundles.Styles.Global" /> <abp-style-bundle name="@BasicThemeBundles.Styles.Global" />
@RenderSection("styles", false) @await RenderSectionAsync("styles", false)
</head> </head>
<body class="abp-account-layout"> <body class="abp-account-layout">
@ -71,7 +71,7 @@
<script type="text/javascript" src="~/Abp/ApplicationConfigurationScript"></script> <script type="text/javascript" src="~/Abp/ApplicationConfigurationScript"></script>
<script type="text/javascript" src="~/Abp/ServiceProxyScript"></script> <script type="text/javascript" src="~/Abp/ServiceProxyScript"></script>
@RenderSection("scripts", false) @await RenderSectionAsync("scripts", false)
</body> </body>
</html> </html>

4
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Application.cshtml

@ -23,7 +23,7 @@
<abp-style-bundle name="@BasicThemeBundles.Styles.Global" /> <abp-style-bundle name="@BasicThemeBundles.Styles.Global" />
@RenderSection("styles", false) @await RenderSectionAsync("styles", false)
</head> </head>
<body class="abp-application-layout"> <body class="abp-application-layout">
@ -39,7 +39,7 @@
<script type="text/javascript" src="~/Abp/ApplicationConfigurationScript"></script> <script type="text/javascript" src="~/Abp/ApplicationConfigurationScript"></script>
<script type="text/javascript" src="~/Abp/ServiceProxyScript"></script> <script type="text/javascript" src="~/Abp/ServiceProxyScript"></script>
@RenderSection("scripts", false) @await RenderSectionAsync("scripts", false)
</body> </body>
</html> </html>

4
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Empty.cshtml

@ -22,7 +22,7 @@
<abp-style-bundle name="@BasicThemeBundles.Styles.Global" /> <abp-style-bundle name="@BasicThemeBundles.Styles.Global" />
@RenderSection("styles", false) @await RenderSectionAsync("styles", false)
</head> </head>
<body class="abp-empty-layout"> <body class="abp-empty-layout">
@ -36,7 +36,7 @@
<script type="text/javascript" src="~/Abp/ApplicationConfigurationScript"></script> <script type="text/javascript" src="~/Abp/ApplicationConfigurationScript"></script>
<script type="text/javascript" src="~/Abp/ServiceProxyScript"></script> <script type="text/javascript" src="~/Abp/ServiceProxyScript"></script>
@RenderSection("scripts", false) @await RenderSectionAsync("scripts", false)
</body> </body>
</html> </html>

1
framework/src/Volo.Abp.Caching/Volo.Abp.Caching.csproj

@ -18,6 +18,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Volo.Abp.Json\Volo.Abp.Json.csproj" />
<ProjectReference Include="..\Volo.Abp.MultiTenancy\Volo.Abp.MultiTenancy.csproj" /> <ProjectReference Include="..\Volo.Abp.MultiTenancy\Volo.Abp.MultiTenancy.csproj" />
<ProjectReference Include="..\Volo.Abp.Serialization\Volo.Abp.Serialization.csproj" /> <ProjectReference Include="..\Volo.Abp.Serialization\Volo.Abp.Serialization.csproj" />
<ProjectReference Include="..\Volo.Abp.Threading\Volo.Abp.Threading.csproj" /> <ProjectReference Include="..\Volo.Abp.Threading\Volo.Abp.Threading.csproj" />

9
framework/src/Volo.Abp.Caching/Volo/Abp/Caching/AbpCachingModule.cs

@ -1,5 +1,6 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System; using System;
using Volo.Abp.Json;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
using Volo.Abp.Serialization; using Volo.Abp.Serialization;
@ -7,9 +8,11 @@ using Volo.Abp.Threading;
namespace Volo.Abp.Caching namespace Volo.Abp.Caching
{ {
[DependsOn(typeof(AbpThreadingModule))] [DependsOn(
[DependsOn(typeof(AbpSerializationModule))] typeof(AbpThreadingModule),
[DependsOn(typeof(AbpMultiTenancyModule))] typeof(AbpSerializationModule),
typeof(AbpMultiTenancyModule),
typeof(AbpJsonModule))]
public class AbpCachingModule : AbpModule public class AbpCachingModule : AbpModule
{ {
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)

22
framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs

@ -25,11 +25,12 @@ namespace Volo.Abp.Caching
protected ICancellationTokenProvider CancellationTokenProvider { get; } protected ICancellationTokenProvider CancellationTokenProvider { get; }
protected IObjectSerializer ObjectSerializer { get; } //TODO: Create IDistributedCacheSerializer
protected IDistributedCacheSerializer Serializer { get; }
protected ICurrentTenant CurrentTenant { get; } protected ICurrentTenant CurrentTenant { get; }
protected AsyncLock AsyncLock { get; } = new AsyncLock(); //protected AsyncLock AsyncLock { get; } = new AsyncLock();
protected DistributedCacheEntryOptions DefaultCacheOptions; protected DistributedCacheEntryOptions DefaultCacheOptions;
@ -42,8 +43,7 @@ namespace Volo.Abp.Caching
IOptions<DistributedCacheOptions> distributedCacheOption, IOptions<DistributedCacheOptions> distributedCacheOption,
IDistributedCache cache, IDistributedCache cache,
ICancellationTokenProvider cancellationTokenProvider, ICancellationTokenProvider cancellationTokenProvider,
IDistributedCacheSerializer serializer,
IObjectSerializer objectSerializer,
ICurrentTenant currentTenant) ICurrentTenant currentTenant)
{ {
_distributedCacheOption = distributedCacheOption.Value; _distributedCacheOption = distributedCacheOption.Value;
@ -51,7 +51,7 @@ namespace Volo.Abp.Caching
Cache = cache; Cache = cache;
CancellationTokenProvider = cancellationTokenProvider; CancellationTokenProvider = cancellationTokenProvider;
Logger = NullLogger<DistributedCache<TCacheItem>>.Instance; Logger = NullLogger<DistributedCache<TCacheItem>>.Instance;
ObjectSerializer = objectSerializer; Serializer = serializer;
CurrentTenant = currentTenant; CurrentTenant = currentTenant;
SetDefaultOptions(); SetDefaultOptions();
@ -85,7 +85,7 @@ namespace Volo.Abp.Caching
return null; return null;
} }
return ObjectSerializer.Deserialize<TCacheItem>(cachedBytes); return Serializer.Deserialize<TCacheItem>(cachedBytes);
} }
public virtual async Task<TCacheItem> GetAsync( public virtual async Task<TCacheItem> GetAsync(
@ -120,7 +120,7 @@ namespace Volo.Abp.Caching
return null; return null;
} }
return ObjectSerializer.Deserialize<TCacheItem>(cachedBytes); return Serializer.Deserialize<TCacheItem>(cachedBytes);
} }
public TCacheItem GetOrAdd( public TCacheItem GetOrAdd(
@ -135,7 +135,7 @@ namespace Volo.Abp.Caching
return value; return value;
} }
using (AsyncLock.Lock(CancellationTokenProvider.Token)) //using (AsyncLock.Lock(CancellationTokenProvider.Token))
{ {
value = Get(key, hideErrors); value = Get(key, hideErrors);
if (value != null) if (value != null)
@ -164,7 +164,7 @@ namespace Volo.Abp.Caching
return value; return value;
} }
using (await AsyncLock.LockAsync(token)) //using (await AsyncLock.LockAsync(token))
{ {
value = await GetAsync(key, hideErrors, token); value = await GetAsync(key, hideErrors, token);
if (value != null) if (value != null)
@ -191,7 +191,7 @@ namespace Volo.Abp.Caching
{ {
Cache.Set( Cache.Set(
NormalizeKey(key), NormalizeKey(key),
ObjectSerializer.Serialize(value), Serializer.Serialize(value),
options ?? DefaultCacheOptions options ?? DefaultCacheOptions
); );
} }
@ -220,7 +220,7 @@ namespace Volo.Abp.Caching
{ {
await Cache.SetAsync( await Cache.SetAsync(
NormalizeKey(key), NormalizeKey(key),
ObjectSerializer.Serialize(value), Serializer.Serialize(value),
options ?? DefaultCacheOptions, options ?? DefaultCacheOptions,
CancellationTokenProvider.FallbackToProvider(token) CancellationTokenProvider.FallbackToProvider(token)
); );

9
framework/src/Volo.Abp.Caching/Volo/Abp/Caching/IDistributedCacheSerializer.cs

@ -0,0 +1,9 @@
namespace Volo.Abp.Caching
{
public interface IDistributedCacheSerializer
{
byte[] Serialize<T>(T obj);
T Deserialize<T>(byte[] bytes);
}
}

26
framework/src/Volo.Abp.Caching/Volo/Abp/Caching/Utf8JsonDistributedCacheSerializer.cs

@ -0,0 +1,26 @@
using System.Text;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Json;
namespace Volo.Abp.Caching
{
public class Utf8JsonDistributedCacheSerializer : IDistributedCacheSerializer, ITransientDependency
{
protected IJsonSerializer JsonSerializer { get; }
public Utf8JsonDistributedCacheSerializer(IJsonSerializer jsonSerializer)
{
JsonSerializer = jsonSerializer;
}
public byte[] Serialize<T>(T obj)
{
return Encoding.UTF8.GetBytes(JsonSerializer.Serialize(obj));
}
public T Deserialize<T>(byte[] bytes)
{
return (T)JsonSerializer.Deserialize(typeof(T), Encoding.UTF8.GetString(bytes));
}
}
}

4
framework/src/Volo.Abp.Core/Volo.Abp.Core.csproj

@ -24,7 +24,7 @@
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0" /> <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="JetBrains.Annotations" Version="2018.3.0" /> <PackageReference Include="JetBrains.Annotations" Version="2018.3.0" />
<PackageReference Include="Nito.AsyncEx.Coordination" Version="1.0.2" /> <PackageReference Include="Nito.AsyncEx.Coordination" Version="5.0.0" />
<PackageReference Include="Nito.AsyncEx.Context" Version="1.1.0" /> <PackageReference Include="Nito.AsyncEx.Context" Version="5.0.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

4
framework/test/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo/Pages/_Layout.cshtml

@ -20,7 +20,7 @@
<abp-style-bundle name="@StandardBundles.Styles.Global" /> <abp-style-bundle name="@StandardBundles.Styles.Global" />
<link href="~/css/demo.min.css" rel="stylesheet" /> <link href="~/css/demo.min.css" rel="stylesheet" />
@RenderSection("styles", false) @await RenderSectionAsync("styles", false)
</head> </head>
<body> <body>
@ -30,7 +30,7 @@
<abp-script-bundle name="@StandardBundles.Scripts.Global" /> <abp-script-bundle name="@StandardBundles.Scripts.Global" />
@RenderSection("scripts", false) @await RenderSectionAsync("scripts", false)
</body> </body>
</html> </html>

22
modules/account/src/Volo.Abp.Account.Web.IdentityServer/AbpAccountWebIdentityServerModule.cs

@ -1,4 +1,7 @@
using Volo.Abp.IdentityServer; using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Identity.AspNetCore;
using Volo.Abp.IdentityServer;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.VirtualFileSystem; using Volo.Abp.VirtualFileSystem;
@ -10,12 +13,29 @@ namespace Volo.Abp.Account.Web
)] )]
public class AbpAccountWebIdentityServerModule : AbpModule public class AbpAccountWebIdentityServerModule : AbpModule
{ {
public override void PreConfigureServices(ServiceConfigurationContext context)
{
context.Services.PreConfigure<AbpIdentityAspNetCoreOptions>(options =>
{
options.ConfigureAuthentication = false;
});
}
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)
{ {
Configure<VirtualFileSystemOptions>(options => Configure<VirtualFileSystemOptions>(options =>
{ {
options.FileSets.AddEmbedded<AbpAccountWebIdentityServerModule>("Volo.Abp.Account.Web"); options.FileSets.AddEmbedded<AbpAccountWebIdentityServerModule>("Volo.Abp.Account.Web");
}); });
//TODO: Try to reuse from AbpIdentityAspNetCoreModule
context.Services
.AddAuthentication(o =>
{
o.DefaultScheme = IdentityConstants.ApplicationScheme;
o.DefaultSignInScheme = IdentityConstants.ExternalScheme;
})
.AddIdentityCookies();
} }
} }
} }

2
modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs

@ -1,7 +1,6 @@
using Localization.Resources.AbpUi; using Localization.Resources.AbpUi;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Account.Web.Localization; using Volo.Abp.Account.Web.Localization;
using Volo.Abp.Account.Web.Settings;
using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.Localization;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars;
@ -9,7 +8,6 @@ using Volo.Abp.Identity.AspNetCore;
using Volo.Abp.Localization; using Volo.Abp.Localization;
using Volo.Abp.Localization.Resources.AbpValidation; using Volo.Abp.Localization.Resources.AbpValidation;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.Settings;
using Volo.Abp.UI.Navigation; using Volo.Abp.UI.Navigation;
using Volo.Abp.VirtualFileSystem; using Volo.Abp.VirtualFileSystem;

Loading…
Cancel
Save