-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/267' into develop
- Loading branch information
Showing
11 changed files
with
135 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Collections.Concurrent; | ||
|
||
namespace Simplify.Web.StaticFiles.Cache; | ||
|
||
/// <summary> | ||
/// Provides static files in-memory cache. | ||
/// </summary> | ||
public static class FilesInMemoryCache | ||
{ | ||
// /// <summary> | ||
// /// Gets the static files in-memory cache data. | ||
// /// </summary> | ||
// /// <value> | ||
// /// The static files in-memory cache data.. | ||
// /// </value> | ||
// public static IDictionary<string, byte[]> Data { get; set; } = new Dictionary<string, byte[]>(); | ||
|
||
/// <summary> | ||
/// Gets the static files in-memory cache data. | ||
/// </summary> | ||
public static readonly ConcurrentDictionary<string, byte[]> Items = new(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/Simplify.Web/StaticFiles/Handlers/InMemoryFilesCacheHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Simplify.Web.Http.ResponseWriting; | ||
using Simplify.Web.StaticFiles.Cache; | ||
using Simplify.Web.StaticFiles.Context; | ||
using Simplify.Web.StaticFiles.IO; | ||
|
||
namespace Simplify.Web.StaticFiles.Handlers; | ||
|
||
/// <summary> | ||
/// Provides the in-memory files cache. | ||
/// </summary> | ||
/// <seealso cref="IStaticFileRequestHandler" /> | ||
public class InMemoryFilesCacheHandler(IResponseWriter responseWriter, IStaticFile staticFile) : IStaticFileRequestHandler | ||
{ | ||
/// <summary> | ||
/// Determines whether this handler can handle the file requested. | ||
/// </summary> | ||
/// <param name="context">The context.</param> | ||
/// <returns> | ||
/// <c>true</c> if this handler can handle the file requested; otherwise, <c>false</c>. | ||
/// </returns> | ||
public bool CanHandle(IStaticFileProcessingContext context) => !context.CanBeCached; | ||
|
||
/// <summary> | ||
/// Executes the handler asynchronously. | ||
/// </summary> | ||
/// <param name="context">The context.</param> | ||
/// <param name="response">The response.</param> | ||
public async Task ExecuteAsync(IStaticFileProcessingContext context, HttpResponse response) | ||
{ | ||
response.SetNewReturningFileAttributes(context); | ||
|
||
await responseWriter.WriteAsync(response, FilesInMemoryCache.Items.GetOrAdd(context.RelativeFilePath, staticFile.GetData)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/Simplify.Web/StaticFiles/StaticFileResponseExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Http; | ||
using Simplify.System; | ||
using Simplify.Web.Http.Mime; | ||
using Simplify.Web.Http.ResponseTime; | ||
using Simplify.Web.StaticFiles.Context; | ||
|
||
namespace Simplify.Web.StaticFiles; | ||
|
||
/// <summary> | ||
/// Provides the static file response extensions. | ||
/// </summary> | ||
public static class StaticFileResponseExtensions | ||
{ | ||
/// <summary> | ||
/// Sets the new returning file attributes. | ||
/// </summary> | ||
/// <param name="response">The HTTP response.</param> | ||
/// <param name="context">The static file processing context.</param> | ||
public static void SetNewReturningFileAttributes(this HttpResponse response, IStaticFileProcessingContext context) | ||
{ | ||
response.SetContentMimeType(context.RelativeFilePath); | ||
response.SetLastModifiedTime(context.LastModificationTime); | ||
response.Headers["Expires"] = new DateTimeOffset(TimeProvider.Current.Now.AddYears(1)).ToString("R"); | ||
} | ||
} |