Hyperbee.Pipeline.Caching
1.1.6
See the version list below for details.
dotnet add package Hyperbee.Pipeline.Caching --version 1.1.6
NuGet\Install-Package Hyperbee.Pipeline.Caching -Version 1.1.6
<PackageReference Include="Hyperbee.Pipeline.Caching" Version="1.1.6" />
paket add Hyperbee.Pipeline.Caching --version 1.1.6
#r "nuget: Hyperbee.Pipeline.Caching, 1.1.6"
// Install Hyperbee.Pipeline.Caching as a Cake Addin #addin nuget:?package=Hyperbee.Pipeline.Caching&version=1.1.6 // Install Hyperbee.Pipeline.Caching as a Cake Tool #tool nuget:?package=Hyperbee.Pipeline.Caching&version=1.1.6
Hyperbee.Pipeline.Caching
The Hyperbee.Pipeline.Caching
library is a set of extentsions to Hyperbee.Pipeline
that adds support for caching within a pipeline using Microsoft.Extensions.Caching
libraries.
Examples
For simple pipelines the previous step's return value can be used as the key:
// Takes a string and returns a number
var command = PipelineFactory
.Start<string>()
.PipeCacheAsync( CharacterCountAsync )
.Build();
var result = await command( factory.Create( logger ), "test" );
Assert.AreEqual( 4, result );
Or for more complex the options callback can be used to customize how the results will be cached.
// Takes a string and returns a number
var command = PipelineFactory
.Start<string>()
.PipeCacheAsync( CharacterCountAsync,
( input, options ) =>
{
options.Key = $"custom/{input}";
options.AbsoluteExpirationRelativeToNow = TimeSpan.FromHours( 1 );
return options;
} )
.Build();
var result = await command( factory.Create( logger ), "test" );
Assert.AreEqual( 4, result );
When a set of steps should cache the overload that takes a builder can be used. In this case the inital input will be used at the key and the final step of the nested pipeline will be cached
// Takes a string and returns a number
var command = PipelineFactory
.Start<string>()
.PipeCacheAsync( b => b
.PipeAsync( CharacterCountAsync )
.Pipe( (ctx, arg) => arg + 100 ))
.Build();
var result = await command( factory.Create( logger ), "test" );
Assert.AreEqual( 104, result );
Dependacy Injection
Because this uses the existing DI built into pipelines, caching can be configured with an existing cache:
// Add Memory Cache
services.AddMemoryCache();
// Share with the pipelines
services.AddPipeline( includeAllServices: true );
Or defined seperately as part of the container use for the pipelines:
services.AddPipeline( (factoryServices, rootProvider) =>
{
factoryServices.AddMemoryCache();
factoryServices.AddPipelineDefaultCacheSettings( absoluteExpirationRelativeToNow: TimeSpan.FromHours( 1 ) )
} );
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
-
net8.0
- Hyperbee.Pipeline (>= 1.0.0)
- Microsoft.Extensions.Caching.Abstractions (>= 8.0.0)
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.2.0 | 111 | 8/9/2024 |
1.1.6 | 84 | 5/3/2024 |
1.1.6-develop.240702125702 | 60 | 7/2/2024 |
1.1.6-develop.240506164152 | 66 | 5/6/2024 |