MemoryCache.Analyzers
0.1.0
dotnet add package MemoryCache.Analyzers --version 0.1.0
NuGet\Install-Package MemoryCache.Analyzers -Version 0.1.0
<PackageReference Include="MemoryCache.Analyzers" Version="0.1.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="MemoryCache.Analyzers" Version="0.1.0" />
<PackageReference Include="MemoryCache.Analyzers"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add MemoryCache.Analyzers --version 0.1.0
#r "nuget: MemoryCache.Analyzers, 0.1.0"
#:package MemoryCache.Analyzers@0.1.0
#addin nuget:?package=MemoryCache.Analyzers&version=0.1.0
#tool nuget:?package=MemoryCache.Analyzers&version=0.1.0
MemoryCache.Analyzers
MemoryCache.Analyzers is a Roslyn analyzer that identifies creation of
System.Runtime.Caching.MemoryCache in modern .NET projects. Microsoft's
ASP.NET Core caching guidance
recommends Microsoft.Extensions.Caching.Memory over that compatibility API.
Example
SRC1000 reports the MemoryCache object creation in this C# code:
using System;
using System.Runtime.Caching;
MemoryCache cache = new("orders"); // SRC1000
cache.Set("order:42", "ready", DateTimeOffset.UtcNow.AddMinutes(5));
Use Microsoft.Extensions.Caching.Memory instead:
using System;
using Microsoft.Extensions.Caching.Memory;
using MemoryCache cache = new(new MemoryCacheOptions());
cache.Set("order:42", "ready", TimeSpan.FromMinutes(5));
Install
Install the package in each project to analyze:
dotnet add package MemoryCache.Analyzers
Or add a package reference:
<PackageReference Include="MemoryCache.Analyzers"
Version="0.1.0"
PrivateAssets="all" />
Supported targets
- Language: C#
- Analyzed applications: .NET Standard 2.0, .NET Core, and .NET 5 or later
- Excluded applications: .NET Framework
- Analyzer target framework:
netstandard2.0
SRC1000 reports only object creation for
System.Runtime.Caching.MemoryCache or a type derived from it. Calls such as
Get and Set, other member access, and MemoryCache.Default do not produce
diagnostics.
Rules
| ID | Category | Severity | Code fix | Title |
|---|---|---|---|---|
| SRC1000 | Compatibility | Warning | No | Avoid System.Runtime.Caching.MemoryCache in .NET Core+ |
See the rule reference for implementation details. See Guides for installation, configuration, and migration steps.
For experimental patterns and decorators built on IMemoryCache, see
memory-cache-solutions.
Configure severity
Use .editorconfig to change the severity of SRC1000:
[*.cs]
dotnet_diagnostic.SRC1000.severity = error
Guides
- Install MemoryCache.Analyzers
- Configure MemoryCache.Analyzers
- Migrate from System.Runtime.Caching.MemoryCache
- GetOrCreate is not atomic: cache stampede in IMemoryCache
Build and test
The repository uses the .NET SDK version in global.json.
dotnet build MemoryCache.Analyzers.sln /p:PedanticMode=true
dotnet test MemoryCache.Analyzers.sln --no-build --settings ./build/targets/tests/test.runsettings
License
MemoryCache.Analyzers is licensed under the MIT License.
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
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 |
|---|---|---|
| 0.1.0 | 84 | 10/12/2026 |
| 0.1.0-alpha | 221 | 6/20/2025 |
A changelog is available at https://github.com/rjmurillo/memorycache.analyzers/releases