Skip to content

Commit d2db58d

Browse files
Add reference ICacheKey implementations for absolute and relative URI keys
1 parent 33a6a8d commit d2db58d

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using Microsoft.AspNetCore.Http;
5+
using Microsoft.AspNetCore.Http.Extensions;
6+
using SixLabors.ImageSharp.Web.Commands;
7+
8+
namespace SixLabors.ImageSharp.Web.Caching
9+
{
10+
/// <summary>
11+
/// Creates a cache key based on the request scheme, host, path and commands.
12+
/// </summary>
13+
public class UriAbsoluteCacheKey : ICacheKey
14+
{
15+
/// <inheritdoc/>
16+
public virtual string Create(HttpContext context, CommandCollection commands)
17+
=> UriHelper.BuildAbsolute(context.Request.Scheme, context.Request.Host, context.Request.PathBase, context.Request.Path, QueryString.Create(commands));
18+
}
19+
20+
/// <summary>
21+
/// Creates a cache key based on the lowercased request scheme, host, path and commands.
22+
/// </summary>
23+
public class UriAbsoluteLowercaseCacheKey : UriAbsoluteCacheKey
24+
{
25+
/// <inheritdoc/>
26+
public override string Create(HttpContext context, CommandCollection commands)
27+
=> base.Create(context, commands).ToLowerInvariant();
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using Microsoft.AspNetCore.Http;
5+
using Microsoft.AspNetCore.Http.Extensions;
6+
using SixLabors.ImageSharp.Web.Commands;
7+
8+
namespace SixLabors.ImageSharp.Web.Caching
9+
{
10+
/// <summary>
11+
/// Creates a cache key based on the request path and commands.
12+
/// </summary>
13+
public class UriRelativeCacheKey : ICacheKey
14+
{
15+
/// <inheritdoc/>
16+
public virtual string Create(HttpContext context, CommandCollection commands)
17+
=> UriHelper.BuildRelative(context.Request.PathBase, context.Request.Path, QueryString.Create(commands));
18+
}
19+
20+
/// <summary>
21+
/// Creates a cache key based on the lowercased request path and commands.
22+
/// </summary>
23+
public class UriRelativeLowercaseCacheKey : UriRelativeCacheKey
24+
{
25+
/// <inheritdoc/>
26+
public override string Create(HttpContext context, CommandCollection commands)
27+
=> base.Create(context, commands).ToLowerInvariant();
28+
}
29+
}

0 commit comments

Comments
 (0)