一 读写锁
public async Task<byte[]> GetAsync(string key, CancellationToken token = new CancellationToken()) { _cacheLock.EnterReadLock(); try { return await _cache.GetAsync(GetCacheKey(key), token); } finally { _cacheLock.ExitReadLock(); } } public async Task SetAsync(string key, byte[] value, DistributedCacheEntryOptions options, CancellationToken token = new CancellationToken()) { _cacheLock.EnterWriteLock(); try { await _cache.SetAsync(GetCacheKey(key), value, options, token); } finally { _cacheLock.ExitWriteLock(); } } public async Task RemoveAsync(string key, CancellationToken token = new CancellationToken()) { _cacheLock.EnterWriteLock(); try { await _cache.RemoveAsync(GetCacheKey(key), token); } finally { _cacheLock.ExitWriteLock(); } }
二 待续。。。
标签:CancellationToken,GetCacheKey,core,Lock,cache,token,key,net,cacheLock From: https://www.cnblogs.com/Insist-Y/p/17465262.html