Cache purge tweaking
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
Hi,
We encountered high memory usage by Dapper and mostly due to DynamicParameters.paramReaderCache.
We have multi-tenant application and to overcome parameters sniffing problem we add to some of our queries comment like -- TenantId = XX UserId = YY. I know that we can use RECOMPILE hint, but we intentionally use our approach to let sql server cache execution plans. Also some queries are generated dynamically based on user selection (filters, columns etc.).
All these leads to a huge amount of different queries and cache entries.
The same about SqlMapper._queryCache, but it is not as big as paramReaderCache because Dapper purges queries that have been executed only once (if I'm not mistaken about it).
Like a workaround we can replace such code
var parameters = new DynamicParameters();
parameters.AddDynamicParams(new { TenantId = tenantId, UserId = userId });
with
var parameters = new DynamicParameters();
parameters.Add("TenantId", tenantId);
parameters.Add("UserId", userId);
But we don't want to restrict our usage of library.
I would be happy try to add ability to configure cache purging policy that wouldn't make any changes to existing behavior by default but would allow to configure some limits for cache size.
But before trying to implement it I would like to ask if you are open to such changes and if you have any suggestions how to do it in the best way.
Thanks in advance!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading DynamicParameters.paramReaderCache and SqlMapper._queryCache, including the current behavior that purges queries executed only once. The issue proposes configurable cache-size or purge limits while preserving existing behavior by default; the scope and policy still need agreement before implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- backend, databases, performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100