Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
Dapper
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
Dapper
Commits
8ed5f615
Commit
8ed5f615
authored
Jul 22, 2011
by
mgravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add automatic collection
parent
724caf1e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
0 deletions
+27
-0
.hgignore
.hgignore
+1
-0
SqlMapper.cs
Dapper/SqlMapper.cs
+26
-0
No files found.
.hgignore
View file @
8ed5f615
...
...
@@ -8,3 +8,4 @@ syntax: glob
glob:Dapper.Contrib/NuGet.exe
*.nupkg
*/NuGet.exe
_ReSharper.*
Dapper/SqlMapper.cs
View file @
8ed5f615
...
...
@@ -135,8 +135,34 @@ private static void PurgeQueryCache(Identity key)
static
readonly
System
.
Collections
.
Concurrent
.
ConcurrentDictionary
<
Identity
,
CacheInfo
>
_queryCache
=
new
System
.
Collections
.
Concurrent
.
ConcurrentDictionary
<
Identity
,
CacheInfo
>();
private
static
void
SetQueryCache
(
Identity
key
,
CacheInfo
value
)
{
if
(
Interlocked
.
Increment
(
ref
collect
)==
COLLECT_PER_ITEMS
)
{
CollectCacheGarbage
();
}
_queryCache
[
key
]
=
value
;
}
private
static
void
CollectCacheGarbage
()
{
try
{
foreach
(
var
pair
in
_queryCache
)
{
if
(
pair
.
Value
.
GetHitCount
()
<=
COLLECT_HIT_COUNT_MIN
)
{
CacheInfo
cache
;
_queryCache
.
TryRemove
(
pair
.
Key
,
out
cache
);
}
}
}
finally
{
Interlocked
.
Exchange
(
ref
collect
,
0
);
}
}
private
const
int
COLLECT_PER_ITEMS
=
1000
,
COLLECT_HIT_COUNT_MIN
=
0
;
private
static
int
collect
;
private
static
bool
TryGetQueryCache
(
Identity
key
,
out
CacheInfo
value
)
{
if
(
_queryCache
.
TryGetValue
(
key
,
out
value
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment