MemoryCache.Analyzers 0.1.0

dotnet add package MemoryCache.Analyzers --version 0.1.0
                    
NuGet\Install-Package MemoryCache.Analyzers -Version 0.1.0
                    
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="MemoryCache.Analyzers" Version="0.1.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MemoryCache.Analyzers" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="MemoryCache.Analyzers">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MemoryCache.Analyzers --version 0.1.0
                    
#r "nuget: MemoryCache.Analyzers, 0.1.0"
                    
#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.
#:package MemoryCache.Analyzers@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MemoryCache.Analyzers&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=MemoryCache.Analyzers&version=0.1.0
                    
Install as a Cake Tool

MemoryCache.Analyzers

NuGet Version Main build

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

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.

There are no supported framework assets in this package.

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