{"id":18924597,"url":"https://github.com/app-vnext/polly.caching.memorycache","last_synced_at":"2025-04-15T12:32:37.330Z","repository":{"id":60774017,"uuid":"71005923","full_name":"App-vNext/Polly.Caching.MemoryCache","owner":"App-vNext","description":"MemoryCache plugin for the Polly Cache policy","archived":false,"fork":false,"pushed_at":"2020-06-25T09:52:22.000Z","size":114,"stargazers_count":44,"open_issues_count":7,"forks_count":19,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-04-14T09:18:42.908Z","etag":null,"topics":["cache","caching","memorycache","polly"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/App-vNext.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-15T18:28:28.000Z","updated_at":"2024-12-16T04:04:58.000Z","dependencies_parsed_at":"2022-10-04T15:30:50.883Z","dependency_job_id":null,"html_url":"https://github.com/App-vNext/Polly.Caching.MemoryCache","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/App-vNext%2FPolly.Caching.MemoryCache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/App-vNext%2FPolly.Caching.MemoryCache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/App-vNext%2FPolly.Caching.MemoryCache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/App-vNext%2FPolly.Caching.MemoryCache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/App-vNext","download_url":"https://codeload.github.com/App-vNext/Polly.Caching.MemoryCache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249072475,"owners_count":21208193,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","caching","memorycache","polly"],"created_at":"2024-11-08T11:07:21.596Z","updated_at":"2025-04-15T12:32:37.076Z","avatar_url":"https://github.com/App-vNext.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Polly.Caching.Memory\n\nThis repo contains the MemoryCache plugin for the [Polly](https://github.com/App-vNext/Polly) [Cache policy](https://github.com/App-vNext/Polly/wiki/Cache).  The current version targets .NET Standard 1.3 (for .NET Core1.x), .NET Standard 2.0 (for .NET Core 2.x and .NET Framework 4.x), and .NET Standard 2.1 (for .NET Core 3.x).\n\n[![NuGet version](https://badge.fury.io/nu/Polly.Caching.Memory.svg)](https://badge.fury.io/nu/Polly.Caching.Memory) [![Build status](https://ci.appveyor.com/api/projects/status/pgd89nfdr9u4ig8m?svg=true)](https://ci.appveyor.com/project/joelhulen/polly-caching-Memory) [![Slack Status](http://www.pollytalk.org/badge.svg)](http://www.pollytalk.org)\n\n## What is Polly?\n\n[Polly](https://github.com/App-vNext/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.\n\nPolly is a member of the [.NET Foundation](https://www.dotnetfoundation.org/about)!\n\n**Keep up to date with new feature announcements, tips \u0026 tricks, and other news through [www.thepollyproject.org](http://www.thepollyproject.org)**\n\n![](https://raw.github.com/App-vNext/Polly/master/Polly-Logo.png)\n\n# Installing Polly.Caching.Memory via NuGet\n\n    Install-Package Polly.Caching.Memory\n\n\n# Supported targets\n\nPolly.Caching.Memory \u0026gt;= v3.0.2 supports .NET Standard 1.3, .NET Standard 2.0 and .NET Standard 2.1.\n\nPolly.Caching.Memory \u0026gt;= v2.0 supports .NET Standard 1.3 and .NET Standard 2.0.\n\nPolly.Caching.MemoryCache \u0026lt;v2.0 supports .NET4.0, .NET4.5 and .NetStandard 1.3\n\n## Dependency compatibility with Polly\n\nPolly.Caching.Memory \u0026gt;=v3.0.2 requires:\n\n+ [Polly](https://nuget.org/packages/polly) \u003e= v7.1.1.\n\nPolly.Caching.Memory \u0026gt;=v3.0 amd \u0026lt;v3.0.2 requires:\n\n+ [Polly](https://nuget.org/packages/polly) \u003e= v7.0.0.\n\nPolly.Caching.Memory \u0026gt;=v2.0.1 and \u0026lt;v3 requires:\n\n+ [Polly](https://nuget.org/packages/polly) \u003e= v6.1.1 and \u0026lt;v7.\n\nPolly.Caching.Memory v2.0.0 requires:\n\n+ [Polly](https://nuget.org/packages/polly) \u003e= v6.0.1 and \u0026lt;=v6.1.0.\n\nPolly.Caching.MemoryCache v1.* requires:\n\n+ [Polly](https://nuget.org/packages/polly) \u003e=v5.9.0 and \u0026lt;v6.\n\n# How to use the Polly.Caching.Memory plugin\n\n### Example: Direct creation of CachePolicy (no DI)\n\n```csharp\n// This approach creates a CachePolicy directly, with its own Microsoft.Extensions.Caching.Memory.MemoryCache instance:\nMicrosoft.Extensions.Caching.Memory.IMemoryCache memoryCache \n   = new Microsoft.Extensions.Caching.Memory.MemoryCache(new Microsoft.Extensions.Caching.Memory.MemoryCacheOptions());\nPolly.Caching.Memory.MemoryCacheProvider memoryCacheProvider \n   = new Polly.Caching.Memory.MemoryCacheProvider(memoryCache);\n\n// Create a Polly cache policy using that Polly.Caching.Memory.MemoryCacheProvider instance.\nvar cachePolicy = Policy.Cache(memoryCacheProvider, TimeSpan.FromMinutes(5));\n```\n\n### Example: Configure CachePolicy via MemoryCacheProvider in StartUp, for DI\n\n```csharp\n// (We pass a whole PolicyRegistry by dependency injection rather than the individual policy, \n// on the assumption the app will probably use multiple policies.)\n\npublic class Startup\n{\n    public void ConfigureServices(IServiceCollection services)\n    {\n        services.AddMemoryCache();\n        services.AddSingleton\u003cPolly.Caching.IAsyncCacheProvider, Polly.Caching.Memory.MemoryCacheProvider\u003e();\n\n        services.AddSingleton\u003cPolly.Registry.IReadOnlyPolicyRegistry\u003cstring\u003e, Polly.Registry.PolicyRegistry\u003e((serviceProvider) =\u003e\n        {\n            PolicyRegistry registry = new PolicyRegistry();\n            registry.Add(\"myCachePolicy\", \n                Policy.CacheAsync\u003cHttpResponseMessage\u003e(\n                    serviceProvider\n                        .GetRequiredService\u003cIAsyncCacheProvider\u003e()\n                        .AsyncFor\u003cHttpResponseMessage\u003e(),\n                    TimeSpan.FromMinutes(5)));\n            return registry;\n        });\n\n        // ...\n    }\n}\n\n// At the point of use, inject the policyRegistry and retrieve the policy:\n// (magic string \"myCachePolicy\" only hard-coded here to keep the example simple) \npublic MyController(IReadOnlyPolicyRegistry\u003cstring\u003e policyRegistry)\n{\n    var _cachePolicy = policyRegistry.Get\u003cIAsyncPolicy\u003cHttpResponseMessage\u003e\u003e(\"myCachePolicy\"); \n    // ...\n}\n\n```\n\nFor many more configuration options and usage examples of the main Polly `CachePolicy`, see the [main Polly readme](https://github.com/App-vNext/Polly#cache) and [deep doco on the Polly wiki](https://github.com/App-vNext/Polly/wiki/Cache).\n\n## Note\n\n`Polly.Caching.Memory.MemoryCacheProvider : ISyncCacheProvider, IAsyncCacheProvider` is non-generic as the underlying `Microsoft.Extensions.Caching.Memory.IMemoryCache` is non-generic.  However, when defining a generic Polly cache policy `Policy.Cache/CacheAsync\u003cTResult\u003e(...)`, some overloads require a generic `ISyncCacheProvider\u003cTResult\u003e` or `IAsyncCacheProvider\u003cTResult\u003e`.  \n\nIn this case, use the extensions methods `MemoryCacheProvider.For\u003cTResult\u003e()` or `MemoryCacheProvider.AsyncFor\u003cTResult\u003e()`, as shown in the ASP.NET Core example above, to obtain a generic `ISyncCacheProvider\u003cTResult\u003e` or `IAsyncCacheProvider\u003cTResult\u003e`.\n\n# Release notes\n\nFor details of changes by release see the [change log](CHANGELOG.md).  \n\n\n# Acknowledgements\n\n* [@reisenberger](https://github.com/reisenberger) - MemoryCache implementation\n* [@seanfarrow](https://github.com/seanfarrow) and [@reisenberger](https://github.com/reisenberger) - Initial caching architecture in the main Polly repo\n* [@kesmy](https://github.com/kesmy) - original structuring of the build for msbuild15, in the main Polly repo\n* [@seanfarrow](https://github.com/seanfarrow) - v2.0 update to Signed packages only to correspond with Polly v6.0.1\n* [@reisenberger](https://github.com/reisenberger) - Update to Polly v7.0.0\n\n\n# Instructions for Contributing\n\nPlease check out our [Wiki](https://github.com/App-vNext/Polly/wiki/Git-Workflow) 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!\n\nSince Polly is part of the .NET Foundation, we ask our contributors to abide by their [Code of Conduct](https://www.dotnetfoundation.org/code-of-conduct).\n\nAlso, we've stood up a [Slack](http://www.pollytalk.org) channel for easier real-time discussion of ideas and the general direction of Polly as a whole. Be sure to [join the conversation](http://www.pollytalk.org) today!\n\n# License\n\nLicensed under the terms of the [New BSD License](http://opensource.org/licenses/BSD-3-Clause)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapp-vnext%2Fpolly.caching.memorycache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapp-vnext%2Fpolly.caching.memorycache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapp-vnext%2Fpolly.caching.memorycache/lists"}