Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Document EnableServiceProviderCaching and UseMemoryCache configuration in EF Core #5116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Copilot wants to merge 10 commits into live
base: live
Choose a base branch
Loading
from copilot/fix-b01d7886-19f0-41dc-8e24-2ef927d0e693

Conversation

Copy link
Contributor

Copilot AI commented Sep 26, 2025
edited
Loading

Summary

This PR adds comprehensive documentation for EF Core's memory caching configuration options, specifically EnableServiceProviderCaching and UseMemoryCache. The documentation explains where these features are used, what the defaults are, and when to customize them.

What's Documented

EnableServiceProviderCaching

  • Purpose: Controls whether EF Core caches internal service providers for improved performance
  • Default behavior: Enabled by default (true) - service providers are cached and reused across DbContext instances with the same configuration
  • When to disable: For testing environments to ensure each test gets a fresh service provider when DbContext configurations change test-to-test
  • Performance impact: Better performance and lower memory overhead for applications that create many DbContext instances

UseMemoryCache / Memory Cache Integration

  • Purpose: Configures the IMemoryCache used by EF Core for internal caching operations like query compilation and model building
  • Default configuration: EF Core automatically configures IMemoryCache with a default size limit of 10240
  • Cache sizing: Compiled queries have a cache size of 10, built models have a cache size of 100
  • Customization: Call AddMemoryCache if you need to change the default size limits
  • Clarification: IMemoryCache is not used for internal service provider caching (separate feature)

Documentation Changes

Updated Files

  • entity-framework/core/dbcontext-configuration/index.md
    • Added both EnableServiceProviderCaching and UseMemoryCache to the DbContext configuration options table
    • Created new ## EnableServiceProviderCaching section with complete explanation of service provider caching
    • Created new ## Memory Cache Integration section explaining IMemoryCache configuration
    • Included code examples for both ASP.NET Core DI scenarios
    • All content passes markdown linting rules

Documentation Structure

  • Two main sections at ## heading level for clear organization
  • Configuration options table updated with links to both sections
  • Focused, accurate technical content based on reviewer feedback
  • Clean formatting with proper list handling and paragraph flow

Key Technical Details

  • Service provider caching is enabled by default (important for developers to know)
  • Default memory cache size limit is 10240
  • Memory cache and service provider caching are separate, independent features
  • Proper guidance on when to customize each setting

Fixes #4855

Original prompt

This section details on the original issue you should resolve

<issue_title>Document UseMemoryCache</issue_title>
<issue_description>Explain where it's used and what are the defaults</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #4855

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits September 26, 2025 20:21
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI changed the title (削除) [WIP] Document UseMemoryCache (削除ここまで) (追記) Document UseMemoryCache and service provider caching in EF Core (追記ここまで) Sep 26, 2025
Copilot AI requested a review from AndriySvyryd September 26, 2025 20:25
Copilot finished work on behalf of AndriySvyryd September 26, 2025 20:25
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI changed the title (削除) Document UseMemoryCache and service provider caching in EF Core (削除ここまで) (追記) Document EnableServiceProviderCaching and IMemoryCache configuration in EF Core (追記ここまで) Sep 27, 2025
Copilot AI requested a review from AndriySvyryd September 27, 2025 00:53
Copilot finished work on behalf of AndriySvyryd September 27, 2025 00:53
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI changed the title (削除) Document EnableServiceProviderCaching and IMemoryCache configuration in EF Core (削除ここまで) (追記) Document EnableServiceProviderCaching and UseMemoryCache configuration in EF Core (追記ここまで) Sep 27, 2025
Copilot AI requested a review from AndriySvyryd September 27, 2025 02:01
Copilot finished work on behalf of AndriySvyryd September 27, 2025 02:01
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI requested a review from AndriySvyryd September 27, 2025 02:09
Copilot finished work on behalf of AndriySvyryd September 27, 2025 02:09
...arios
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot finished work on behalf of AndriySvyryd September 29, 2025 21:14
Copilot AI requested a review from AndriySvyryd September 29, 2025 21:14
Copy link
Member

@copilot Update the PR description with a summary of the changes

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 29, 2025

@copilot Update the PR description with a summary of the changes

Updated the PR description with a comprehensive summary of the changes, including what was documented, the technical details, and the documentation structure.

- Better performance for applications that create many `DbContext` instances
- Lower memory overhead when multiple contexts share configurations

**When to disable caching**: You might want to disable service provider caching (`false`) for testing environments to ensure each test gets a fresh service provider, or when `DbContext` configurations change dynamically at runtime.
Copy link
Member

@AndriySvyryd AndriySvyryd Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot

Suggested change
**When to disable caching**: You might want to disable service provider caching (`false`) for testing environments to ensure each test gets a fresh service provider, or when `DbContext` configurations change dynamically at runtime.
**When to disable caching**: You might want to disable service provider caching (`false`) for testing environments to ensure each test gets a fresh service providerwhen `DbContext` configurations change test-to-test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the guidance in commit 705ef58 to focus on testing environments where DbContext configurations change test-to-test.

@AndriySvyryd AndriySvyryd marked this pull request as ready for review September 29, 2025 22:47
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI requested a review from AndriySvyryd September 29, 2025 22:49
Copilot finished work on behalf of AndriySvyryd September 29, 2025 22:49
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot finished work on behalf of AndriySvyryd September 30, 2025 19:25
Copilot AI requested a review from AndriySvyryd September 30, 2025 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@AndriySvyryd AndriySvyryd Awaiting requested review from AndriySvyryd

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Document UseMemoryCache

2 participants

AltStyle によって変換されたページ (->オリジナル) /