IL.RulesBasedOutputCache 1.1.3

dotnet add package IL.RulesBasedOutputCache --version 1.1.3                
NuGet\Install-Package IL.RulesBasedOutputCache -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="IL.RulesBasedOutputCache" Version="1.1.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IL.RulesBasedOutputCache --version 1.1.3                
#r "nuget: IL.RulesBasedOutputCache, 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 IL.RulesBasedOutputCache as a Cake Addin
#addin nuget:?package=IL.RulesBasedOutputCache&version=1.1.3

// Install IL.RulesBasedOutputCache as a Cake Tool
#tool nuget:?package=IL.RulesBasedOutputCache&version=1.1.3                

Output cache middleware

  • Rules based output cache middleware - inspired by Microsoft output cache

Setup

v5 startup files structure (Program.cs and Startup.cs files)

ConfigureServices(IServiceCollection services)
services.AddRulesBasedOutputCache();

...

app.UseRulesBasedOutputCache();

v6+ startup files structure (Single Progam.cs file)

var builder = WebApplication.CreateBuilder(args);
builder.AddRulesBasedOutputCache();

...
var app = builder.Build();
app.UseRulesBasedOutputCache();

Tags management

In order to tag cache entries there are few extension methods available (IL.RulesBasedOutputCache.Helpers namespace):

  • void ApplyCustomOutputCacheTagToCurrentRequest(this HttpContext context, string tag)
  • void ApplyCustomOutputCacheTagsToCurrentRequest(this HttpContext context, HashSet<string> tags)
  • void IgnoreRulesBasedOutputCacheForCurrentRequest(this HttpContext context)

which you can use to apply one or multiple tags to current request/potential cache entry.

Tags can be used for cache invalidation.

Cache invalidation

As library heavily relies on microsoft implementation of output cache you can use IOutputCacheStore for eviction of cached entries by their tags.

await _store.EvictByTagAsync("CacheTag", HttpContext.RequestAborted);

Extra configurations

.AddRulesBasedOutputCache() has optional parameter for inline service configuration.

Another invariant is providing configuration from appsettings.json file. Library comes with schema file, that you will be able to select as schema in your own appsettings.json file.

Configuration parameters:

  • OutputCacheEnabled - allows to disable module completely
  • DefaultCacheTimeout - default expiration time for your cache entries, if not set up on the rule itself
  • CachingRules - array of caching rules the system will have on application startup
  • SqlConnectionStringName - optional string parameter, if provided will replace in-memory storage for rules with SQL based. You need to provide only the NAME of connection string, not the connection string itself. Database and/or required table will br created automatically, all the needed migrations will be automatically applied with new versions of library.
  • OutputCacheAdminPanelEnabled - enables Admin panel api and access to admin panel page, which is available by url /rulesBasedCache/adminPanel

Caching rule parameters:

  • RuleTemplate - template to be matched in order for rule to become active. Examples:
    • /test for ExactPath match rule
    • /test/* for Regex match rule
    • .js for FileExtension match rule. Also supports pipe separated list: '.js|.css|.html|.png'
  • RuleAction - Allow or Dissalow
  • RuleType - ExactPath, Regex or FileExtension
  • VaryByQueryString - includes query string to cache key
  • VaryByUser - includes HttpContext.User.Identity.Name to cache key
  • VaryByHost - includes host string to cache key
  • VaryByCulture - includes both CultureInfo.CurrentCulture and CultureInfo.CurrentUICulture to cache key
  • ResponseExpirationTimeSpan - specific expiration time for rule. TimeSpan format ("00:00:00")

Rules order

Rules have enforced order based on their RuleAction and RuleType. <br/> Main ordering parameter is RuleAction where Dissallow has more priority than Allow. <br/> Then rules are ordered by RuleType where priority goes as follows(low to high): FileExtension, ExactPath, Regex. <br/> Only rule with highest priority will be resolved per request.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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 is compatible.  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. 
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 34 7/15/2024
1.1.2 93 7/10/2024
1.1.1 64 7/9/2024
1.1.0 50 7/9/2024
1.0.19 215 5/13/2024
1.0.18 110 5/8/2024
1.0.17 245 10/22/2023
1.0.15 137 10/4/2023
1.0.9 120 9/23/2023
1.0.4 95 9/22/2023
1.0.3 129 9/21/2023
1.0.2 109 9/21/2023
1.0.1 114 9/21/2023
1.0.0 97 9/21/2023