Hyperbee.Pipeline.Caching 1.1.6

dotnet add package Hyperbee.Pipeline.Caching --version 1.1.6
NuGet\Install-Package Hyperbee.Pipeline.Caching -Version 1.1.6
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="Hyperbee.Pipeline.Caching" Version="1.1.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Hyperbee.Pipeline.Caching --version 1.1.6
#r "nuget: Hyperbee.Pipeline.Caching, 1.1.6"
#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 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Hyperbee.Pipeline.Caching:

Package Downloads
Hyperbee.Pipeline.Benchmark

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.6 64 5/3/2024
1.1.6-develop.240702125702 28 7/2/2024
1.1.6-develop.240506164152 56 5/6/2024