Polly.Caching.MemoryCache-Signed 1.0.0

Polly.Caching.MemoryCache is a plug-in for the .NET OSS resilience library Polly, supporting System.Runtime.Caching.MemoryCache as a provider for Polly's CachePolicy.

There is a newer version of this package available.
See the version list below for details.
Install-Package Polly.Caching.MemoryCache-Signed -Version 1.0.0
dotnet add package Polly.Caching.MemoryCache-Signed --version 1.0.0
<PackageReference Include="Polly.Caching.MemoryCache-Signed" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Polly.Caching.MemoryCache-Signed --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Polly.Caching.MemoryCache

This repo contains the MemoryCache plugin for the Polly Cache policy. It targets .NET 4.0, .NET 4.5 and .NET Standard 1.3.

What is Polly?

Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, Cache aside and Fallback in a fluent and thread-safe manner. Polly targets .NET 4.0, .NET 4.5 and .NET Standard 1.1.

Polly is a member of the .NET Foundation!

Keep up to date with new feature announcements, tips & tricks, and other news through www.thepollyproject.org

Installing Polly.Caching.MemoryCache via NuGet

Install-Package Polly.Caching.MemoryCache

You can install the Strongly Named version via:

Install-Package Polly.Caching.MemoryCache-Signed

Supported targets

Polly.Caching.MemoryCache supports .NET4.0, .NET4.5 and .NetStandard 1.3.

Dependencies

Polly.Caching.MemoryCache works with Polly v5.4.0 and above.

How to use the Polly.Caching.MemoryCache plugin

// (1a): Create a MemoryCacheProvider instance in the .NET Framework, using the Polly.Caching.MemoryCache nuget package.
// (full namespaces and types only shown here for disambiguation)
Polly.Caching.MemoryCache.MemoryCacheProvider memoryCacheProvider 
   = new Polly.Caching.MemoryCache.MemoryCacheProvider(System.Runtime.Caching.MemoryCache.Default);

// Or (1b): Create a MemoryCacheProvider instance in .NET Core / .NET Standard.
// (full namespaces and types only shown here for disambiguation)
// NB Only if you want to create your own Microsoft.Extensions.Caching.Memory.MemoryCache instance:
Microsoft.Extensions.Caching.Memory.IMemoryCache memoryCache 
   = new Microsoft.Extensions.Caching.Memory.MemoryCache(new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions());
Polly.Caching.MemoryCache.MemoryCacheProvider memoryCacheProvider 
   = new Polly.Caching.MemoryCache.MemoryCacheProvider(memoryCache);

// (2) Create a Polly cache policy using that Polly.Caching.MemoryCache.MemoryCacheProvider instance.
var cachePolicy = Policy.Cache(memoryCacheProvider, TimeSpan.FromMinutes(5));



// Or (1c): Configure by dependency injection within ASP.NET Core
// See https://docs.microsoft.com/en-us/aspnet/core/performance/caching/memory
// and https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection#registering-your-own-services

// (In this example we choose to pass a whole PolicyRegistry by dependency injection rather than the individual policy, on the assumption the webapp will probably use multiple policies across the app.)

// For example: 
public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMemoryCache();
        services.AddSingleton<Polly.Registry.IPolicyRegistry<string>, Polly.Registry.PolicyRegistry>();
        // ...
    }

    public void Configure(..., IPolicyRegistry<string> policyRegistry, IMemoryCache memoryCache)
    {
        Polly.Caching.MemoryCache.MemoryCacheProvider memoryCacheProvider 
            = new Polly.Caching.MemoryCache.MemoryCacheProvider(memoryCache);
        var cachePolicy = Policy.Cache(memoryCacheProvider, TimeSpan.FromMinutes(5));
        policyRegistry.Add("myCachePolicy", cachePolicy);
        // ...
    }
}

// In a controller, inject the policyRegistry and retrieve the policy:
// (magic string "myCachePolicy" only hard-coded here to keep the example simple!) 
public MyController(IPolicyRegistry<string> policyRegistry)
{
    _cachePolicy = policyRegistry["myCachePolicy"];
    // ...
}

For many more configuration options and usage examples of the main Polly CachePolicy, see the main Polly readme and deep doco on the Polly wiki.

Release notes

For details of changes by release see the change log.

Acknowledgements

Instructions for Contributing

Please check out our Wiki for contributing guidelines. We are following the excellent GitHub Flow process, and would like to make sure you have all of the information needed to be a world-class contributor!

Since Polly is part of the .NET Foundation, we ask our contributors to abide by their Code of Conduct.

Also, we've stood up a Slack channel for easier real-time discussion of ideas and the general direction of Polly as a whole. Be sure to join the conversation today!

License

Licensed under the terms of the New BSD License

Polly.Caching.MemoryCache

This repo contains the MemoryCache plugin for the Polly Cache policy. It targets .NET 4.0, .NET 4.5 and .NET Standard 1.3.

What is Polly?

Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, Cache aside and Fallback in a fluent and thread-safe manner. Polly targets .NET 4.0, .NET 4.5 and .NET Standard 1.1.

Polly is a member of the .NET Foundation!

Keep up to date with new feature announcements, tips & tricks, and other news through www.thepollyproject.org

Installing Polly.Caching.MemoryCache via NuGet

Install-Package Polly.Caching.MemoryCache

You can install the Strongly Named version via:

Install-Package Polly.Caching.MemoryCache-Signed

Supported targets

Polly.Caching.MemoryCache supports .NET4.0, .NET4.5 and .NetStandard 1.3.

Dependencies

Polly.Caching.MemoryCache works with Polly v5.4.0 and above.

How to use the Polly.Caching.MemoryCache plugin

// (1a): Create a MemoryCacheProvider instance in the .NET Framework, using the Polly.Caching.MemoryCache nuget package.
// (full namespaces and types only shown here for disambiguation)
Polly.Caching.MemoryCache.MemoryCacheProvider memoryCacheProvider 
   = new Polly.Caching.MemoryCache.MemoryCacheProvider(System.Runtime.Caching.MemoryCache.Default);

// Or (1b): Create a MemoryCacheProvider instance in .NET Core / .NET Standard.
// (full namespaces and types only shown here for disambiguation)
// NB Only if you want to create your own Microsoft.Extensions.Caching.Memory.MemoryCache instance:
Microsoft.Extensions.Caching.Memory.IMemoryCache memoryCache 
   = new Microsoft.Extensions.Caching.Memory.MemoryCache(new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions());
Polly.Caching.MemoryCache.MemoryCacheProvider memoryCacheProvider 
   = new Polly.Caching.MemoryCache.MemoryCacheProvider(memoryCache);

// (2) Create a Polly cache policy using that Polly.Caching.MemoryCache.MemoryCacheProvider instance.
var cachePolicy = Policy.Cache(memoryCacheProvider, TimeSpan.FromMinutes(5));



// Or (1c): Configure by dependency injection within ASP.NET Core
// See https://docs.microsoft.com/en-us/aspnet/core/performance/caching/memory
// and https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection#registering-your-own-services

// (In this example we choose to pass a whole PolicyRegistry by dependency injection rather than the individual policy, on the assumption the webapp will probably use multiple policies across the app.)

// For example: 
public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMemoryCache();
        services.AddSingleton<Polly.Registry.IPolicyRegistry<string>, Polly.Registry.PolicyRegistry>();
        // ...
    }

    public void Configure(..., IPolicyRegistry<string> policyRegistry, IMemoryCache memoryCache)
    {
        Polly.Caching.MemoryCache.MemoryCacheProvider memoryCacheProvider 
            = new Polly.Caching.MemoryCache.MemoryCacheProvider(memoryCache);
        var cachePolicy = Policy.Cache(memoryCacheProvider, TimeSpan.FromMinutes(5));
        policyRegistry.Add("myCachePolicy", cachePolicy);
        // ...
    }
}

// In a controller, inject the policyRegistry and retrieve the policy:
// (magic string "myCachePolicy" only hard-coded here to keep the example simple!) 
public MyController(IPolicyRegistry<string> policyRegistry)
{
    _cachePolicy = policyRegistry["myCachePolicy"];
    // ...
}

For many more configuration options and usage examples of the main Polly CachePolicy, see the main Polly readme and deep doco on the Polly wiki.

Release notes

For details of changes by release see the change log.

Acknowledgements

Instructions for Contributing

Please check out our Wiki for contributing guidelines. We are following the excellent GitHub Flow process, and would like to make sure you have all of the information needed to be a world-class contributor!

Since Polly is part of the .NET Foundation, we ask our contributors to abide by their Code of Conduct.

Also, we've stood up a Slack channel for easier real-time discussion of ideas and the general direction of Polly as a whole. Be sure to join the conversation today!

License

Licensed under the terms of the New BSD License

Release Notes

## 1.0-RC

    - Upgrade to Polly v5.4.0
    - Correctly state RC dependency (Polly v5.4.0)

    ## 0.2-alpha

    - Upgrade to msbuild15 build process
    - Upgrade to Polly v5.3.1

    ## 0.1-alpha

    - Stub repo for Polly.Caching.MemoryCache with first build script

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.1.0 8,634 4/28/2018
1.0.0 451 11/2/2017