-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
93 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Collections.Concurrent; | ||
using Microsoft.Extensions.Caching.Memory; | ||
using ShardingCore.Core.ModelCacheLockerProviders; | ||
using ShardingCore.Helpers; | ||
|
||
namespace Sample.MySql; | ||
|
||
public class DicModelCacheLockerProvider:IModelCacheLockerProvider | ||
{ | ||
private readonly ConcurrentDictionary<string, object> _locks = new ConcurrentDictionary<string, object>(); | ||
public int GetCacheModelLockObjectSeconds() | ||
{ | ||
return 20; | ||
} | ||
|
||
public CacheItemPriority GetCacheItemPriority() | ||
{ | ||
return CacheItemPriority.High; | ||
} | ||
|
||
public int GetCacheEntrySize() | ||
{ | ||
return 1; | ||
} | ||
|
||
public object GetCacheLockObject(object modelCacheKey) | ||
{ | ||
var key = $"{modelCacheKey}"; | ||
Console.WriteLine("-----------------------------------------------DicModelCacheLockerProvider:"+key); | ||
if (!_locks.TryGetValue(key, out var obj)) | ||
{ | ||
obj = new object(); | ||
if (_locks.TryAdd(key, obj)) | ||
{ | ||
return obj; | ||
} | ||
if (!_locks.TryGetValue(key, out obj)) | ||
{ | ||
throw new Exception("错了"); | ||
} | ||
} | ||
return obj; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters