CacheableContentResult 1.1.3

Install-Package CacheableContentResult -Version 1.1.3
dotnet add package CacheableContentResult --version 1.1.3
<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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CacheableContentResult, 1.1.3"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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

Visual Studio 上の ASP.NET MVC Web アプリケーションに NuGet パッケージとして 経由でインストールできます。

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 )

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 703 12/25/2018
1.1.2 743 4/24/2017
1.1.1 639 4/24/2017 963 1/13/2016
1.0.0 1,479 3/9/2013

- Fix: Doesn't work in some cases.
- Update license - MPL v2 and MS-PL dual licenses.
- Add .NET Core applications support.
- Fix: "If-Modified-Since" based cache doesn't work correctly.
- If the function of GetContent property returned null, then respond "HTTP 404 Not Found" status.
- 1st release.