Skip to content

Commit

Permalink
Merge 9b73c6a into cdc2fdb
Browse files Browse the repository at this point in the history
  • Loading branch information
Jalalx committed Dec 23, 2020
2 parents cdc2fdb + 9b73c6a commit 066777a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
5 changes: 3 additions & 2 deletions samples/ZeusCachingSample/Startup.cs
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Extensions.Hosting;
using ZeusCaching;
using System;
using Microsoft.AspNetCore.Http;

namespace ZeusCachingSample
{
Expand All @@ -30,7 +31,7 @@ public void ConfigureServices(IServiceCollection services)
// builder.DisableGlobally(),
builder.AddDefaultProfile(options =>
{
options.UseCachingPredicate((_, req) => !req.Path.StartsWithSegments("/private"));
options.UseCachingPredicate((_, ctx) => !ctx.Request.Path.StartsWithSegments("/private"));
options.UseDistributedCachingAdapter();
options.UseCacheKeyHandler((sp, ctx) =>
{
Expand Down Expand Up @@ -63,7 +64,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddControllers();
}

private object WrapCacheResult(IServiceProvider serviceProvider, object content)
private object WrapCacheResult(IServiceProvider serviceProvider, HttpContext context, object content)
{
return new MyWrapper<object>
{
Expand Down
4 changes: 2 additions & 2 deletions src/ZeusCaching/Services/ZeusCachingService.cs
Expand Up @@ -51,7 +51,7 @@ public async Task ProcessRequestAsync(ZeusCachingContext context, ActionExecutio
return;
}

if (!profileOptions.CachingPredicate(_serviceProvider, context.ExecutionContext.HttpContext.Request))
if (!profileOptions.CachingPredicate(_serviceProvider, context.ExecutionContext.HttpContext))
{
await next();
return;
Expand Down Expand Up @@ -110,7 +110,7 @@ public async Task ProcessRequestAsync(ZeusCachingContext context, ActionExecutio
object wrappedContent;
if (options.WrappingResultHandler != null)
{
wrappedContent = options.WrappingResultHandler(_serviceProvider, content);
wrappedContent = options.WrappingResultHandler(_serviceProvider, context.ExecutionContext.HttpContext, content);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/ZeusCaching/ZeusCaching.csproj
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>0.0.2</Version>
<Version>0.0.3</Version>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
Expand All @@ -12,7 +12,7 @@
<Authors>jalalx</Authors>
<Company />
<Description>Zeus Caching helps using existing dotnet caching extensions easily in your ASP.NET Core Web API applications by simply putting a `[ZeusCache]` attribute on controller action methods.
This package is built from the source file in https://github.com/Jalalx/ZeusCaching/commit/$(GITHUB_SHA)</Description>
This package was built from the source code at https://github.com/Jalalx/ZeusCaching/commit/$(GITHUB_SHA)</Description>
<PackageProjectUrl>https://github.com/Jalalx/ZeusCaching</PackageProjectUrl>
<RepositoryUrl>https://github.com/Jalalx/ZeusCaching</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down
6 changes: 3 additions & 3 deletions src/ZeusCaching/ZeusCachingExtensions.cs
Expand Up @@ -62,10 +62,10 @@ internal static string GetCacheKey(IServiceProvider _, HttpContext context)



internal static bool DefaultCachingPredicate(IServiceProvider _, HttpRequest __) => true;
internal static bool DefaultCachingPredicate(IServiceProvider _, HttpContext __) => true;



internal static object DefaultWrappingResultHandler(IServiceProvider _, object obj) => obj;
internal static object DefaultWrappingResultHandler(IServiceProvider __, HttpContext _, object obj) => obj;
}
}
12 changes: 6 additions & 6 deletions src/ZeusCaching/ZeusCachingProfileOptions.cs
Expand Up @@ -19,8 +19,8 @@ internal ZeusCachingProfileOptions()
internal ZeusCachingProfileOptions(bool isEnabled,
CachingAdapterMode cachingAdapterMode,
Func<IServiceProvider, HttpContext, string> cacheKeyHandler,
Func<IServiceProvider, HttpRequest, bool> cachingPredicate,
Func<IServiceProvider, object, object> wrappingResultHandler)
Func<IServiceProvider, HttpContext, bool> cachingPredicate,
Func<IServiceProvider, HttpContext, object, object> wrappingResultHandler)
{
CachingAdapterMode = cachingAdapterMode;
IsEnabled = isEnabled;
Expand Down Expand Up @@ -127,15 +127,15 @@ public ZeusCachingProfileOptions UseCacheKeyHandler(Func<IServiceProvider, HttpC
/// <summary>
/// Gets or sets the caching profile predicate function.
/// </summary>
internal Func<IServiceProvider, HttpRequest, bool> CachingPredicate { get; private set; }
internal Func<IServiceProvider, HttpContext, bool> CachingPredicate { get; private set; }


/// <summary>
/// Sets a predicate to determine if the request should be cached.
/// </summary>
/// <param name="predicate">A predicate function that determines if the request should be cached.</param>
/// <returns></returns>
public ZeusCachingProfileOptions UseCachingPredicate(Func<IServiceProvider, HttpRequest, bool> predicate)
public ZeusCachingProfileOptions UseCachingPredicate(Func<IServiceProvider, HttpContext, bool> predicate)
{
CachingPredicate = predicate ?? throw new ArgumentNullException(nameof(predicate));
return this;
Expand All @@ -147,15 +147,15 @@ public ZeusCachingProfileOptions UseCachingPredicate(Func<IServiceProvider, Http
/// <summary>
/// Gets or sets the caching profile wrapping handler.
/// </summary>
internal Func<IServiceProvider, object, object> WrappingResultHandler { get; private set; }
internal Func<IServiceProvider, HttpContext, object, object> WrappingResultHandler { get; private set; }


/// <summary>
/// Sets a handler that can be used to wrap the response.
/// </summary>
/// <param name="handler">A handler function that wraps the response.</param>
/// <returns></returns>
public ZeusCachingProfileOptions UseWrappingHandler(Func<IServiceProvider, object, object> handler)
public ZeusCachingProfileOptions UseWrappingHandler(Func<IServiceProvider, HttpContext, object, object> handler)
{
WrappingResultHandler = handler ?? throw new ArgumentNullException(nameof(handler));
return this;
Expand Down
4 changes: 2 additions & 2 deletions tests/ZeusCaching.Tests/ZeusCachingProfileOptionsTests.cs
Expand Up @@ -98,7 +98,7 @@ public void UseCacheKeyHandler_ForDefaultInstance_ActsAsExpected()
public void UseCachingPredicate_ForDefaultInstance_ActsAsExpected()
{
var options = new ZeusCachingProfileOptions();
Func<IServiceProvider, HttpRequest, bool> alwaysTrueHandler = (__, _) => true;
Func<IServiceProvider, HttpContext, bool> alwaysTrueHandler = (__, _) => true;


options.UseCachingPredicate(alwaysTrueHandler);
Expand All @@ -114,7 +114,7 @@ public void UseCachingPredicate_ForDefaultInstance_ActsAsExpected()
public void UseWrappingHandler_ForDefaultInstance_ActsAsExpected()
{
var options = new ZeusCachingProfileOptions();
Func<IServiceProvider, object, object> wrapInResultHandler = (__, content) => new { Result = content };
Func<IServiceProvider, HttpContext, object, object> wrapInResultHandler = (__, _, content) => new { Result = content };


options.UseWrappingHandler(wrapInResultHandler);
Expand Down

0 comments on commit 066777a

Please sign in to comment.