CacheableContentResult 1.1.3

dotnet add package CacheableContentResult --version 1.1.3                
NuGet\Install-Package CacheableContentResult -Version 1.1.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CacheableContentResult" Version="1.1.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CacheableContentResult --version 1.1.3                
#r "nuget: CacheableContentResult, 1.1.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 NuGet Package

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);
    }
  );
}

movie

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 Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.6 is compatible.  netstandard2.0 was computed.  netstandard2.1 was computed. 
.NET Framework net40 is compatible.  net403 was computed.  net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.3 1,407 12/25/2018
1.1.2 1,101 4/24/2017
1.1.1 1,005 4/24/2017
1.1.0.1 1,480 1/13/2016
1.0.0 1,879 3/9/2013

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.