CacheableContentResult 1.1.3
dotnet add package CacheableContentResult --version 1.1.3
NuGet\Install-Package CacheableContentResult -Version 1.1.3
<PackageReference Include="CacheableContentResult" Version="1.1.3" />
paket add CacheableContentResult --version 1.1.3
#r "nuget: CacheableContentResult, 1.1.3"
// Install CacheableContentResult as a Cake Addin
#addin nuget:?package=CacheableContentResult&version=1.1.3
// Install CacheableContentResult as a Cake Tool
#tool nuget:?package=CacheableContentResult&version=1.1.3
CacheableContentResult 
What's this? / これは何か?
This is the class library that is ActionResult of ASP.NET MVC .
This ActionResult class for ASP.NET MVC allows you to send a binary contents response that can cache based on Etag, and/or last modified date, to web browser.
If the cache hit, then this class send "HTTP 304 Not Modified" without calling contents retrieving callback, and witout content body.
これは ASP.NET MVC の ActonResult であるクラスライブラリです。
この ActionResult は Etag および最終更新日によるキャッシュ制御された任意のバイナリコンテンツをWebブラウザに応答することができます。
要求ヘッダの If-Modified-Since および If-Match-None からキャッシュヒットが判断できた場合は、コンテンツ本体を返すことなく、HTTP 304 Not Modified をブラウザに返します。
How to install? / インストール方法
You can install this libray as a NuGet package into your ASP.NET MVC Web Appliction project on Visual Studio via NuGet.org.
Visual Studio 上の ASP.NET MVC Web アプリケーションに NuGet パッケージとして NuGet.org 経由でインストールできます。
PM> Install-Package CacheableContentResult
How to use? / 使い方
public ActionResult Picture(int id)
{
var imagePath = HttpContext.Server.MapPath("~/App_Data/user/{id}/picture.png");
var lastWriteTime = System.IO.File.GetLastWriteTimeUtc(imagePath);
return new CacheableContentResult(
contentType: "image/png",
lastModified: lastWriteTime,
getContent: () =>
{
return System.IO.File.ReadAllBytes(imagePath);
}
);
}
Return the instance of CachebleContentResult class in MVC action method specified with ETag, and/or the date time of last modified, and the function which return the binary content as byte[] to responding you want.
The function which return the content you specified does not call if not needed, then you can implement "lazy loading".
See the example.
MVC アクションメソッド内で、ETag、および/あるいは最終更新日、そして応答に返したいバイナリコンテンツを byte[] で返す関数を指定した CachebleContentResult クラスのインスタンスを返します。
必要となるまでコンテンツを返す関数は呼び出されませんので、遅延読み込みが実装できます。
例は こちら を参照ください。
License / ライセンス
Mozilla Public License Version 2.0 / Microsoft Public License (MS-PL)
(* dual license )
Product | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows |
.NET Core | netcoreapp1.0 netcoreapp1.1 netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1 |
.NET Standard | netstandard1.6 netstandard2.0 netstandard2.1 |
.NET Framework | net40 net403 net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48 net481 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | tizen30 tizen40 tizen60 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
-
.NETFramework 4.0
- Microsoft.AspNet.Mvc (>= 3.0.20105.1)
-
.NETStandard 1.6
- Microsoft.AspNetCore.Mvc (>= 1.0.4)
- NETStandard.Library (>= 1.6.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v.1.1.3
- Fix: Doesn't work in some cases.
v.1.1.2
- Update license - MPL v2 and MS-PL dual licenses.
v.1.1.1
- Add .NET Core applications support.
- Fix: "If-Modified-Since" based cache doesn't work correctly.
v.1.1.0
- If the function of GetContent property returned null, then respond "HTTP 404 Not Found" status.
v.1.0.0
- 1st release.