Added playing song view. Adding styling to playing song. Fixed caching cancellation issue.
This commit is contained in:
@@ -32,30 +32,39 @@ public abstract class Cache<TKey, TValue> : ICache<TKey, TValue> where TKey : no
|
||||
|
||||
SemaphoreSlim lockObject = _locks.GetOrAdd(actualKey, (key) => new SemaphoreSlim(1, 1));
|
||||
|
||||
bool throttlerAcquired = false;
|
||||
bool lockAcquired = false;
|
||||
|
||||
try
|
||||
{
|
||||
await _throttler.WaitAsync(cancellationToken);
|
||||
throttlerAcquired = true;
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
return default;
|
||||
|
||||
await lockObject.WaitAsync(cancellationToken);
|
||||
lockAcquired = true;
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
return default;
|
||||
|
||||
return TryGetValue(actualKey) ?? await FetchAsync2(key, cancellationToken);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
finally
|
||||
{
|
||||
lockObject.Release();
|
||||
if (lockAcquired)
|
||||
lockObject.Release();
|
||||
|
||||
_locks.TryRemove(lockObject, out _);
|
||||
|
||||
_throttler.Release();
|
||||
if (throttlerAcquired)
|
||||
_throttler.Release();
|
||||
}
|
||||
|
||||
//return TryGetValue(actualKey) ?? Refresh(key);
|
||||
}
|
||||
|
||||
private async Task<TValue?> FetchAsync2(TKey key, CancellationToken cancellationToken)
|
||||
|
||||
Reference in New Issue
Block a user