Do not announce/match with limited accounts, lockdowns and trade bans, improve ArchiCacheable

We can totally make use of success previously more often
This commit is contained in:
Archi
2023-02-11 15:58:15 +01:00
parent a0f521d4f4
commit d7e8710333
8 changed files with 165 additions and 34 deletions

View File

@@ -47,9 +47,9 @@ public sealed class ArchiCacheable<T> : IDisposable {
public void Dispose() => InitSemaphore.Dispose();
[PublicAPI]
public async Task<(bool Success, T? Result)> GetValue(EFallback fallback = EFallback.DefaultForType) {
if (!Enum.IsDefined(fallback)) {
throw new InvalidEnumArgumentException(nameof(fallback), (int) fallback, typeof(EFallback));
public async Task<(bool Success, T? Result)> GetValue(ECacheFallback cacheFallback = ECacheFallback.DefaultForType) {
if (!Enum.IsDefined(cacheFallback)) {
throw new InvalidEnumArgumentException(nameof(cacheFallback), (int) cacheFallback, typeof(ECacheFallback));
}
if (IsInitialized && IsRecent) {
@@ -66,11 +66,11 @@ public sealed class ArchiCacheable<T> : IDisposable {
(bool success, T? result) = await ResolveFunction().ConfigureAwait(false);
if (!success) {
return fallback switch {
EFallback.DefaultForType => (false, default(T?)),
EFallback.FailedNow => (false, result),
EFallback.SuccessPreviously => (false, InitializedValue),
_ => throw new InvalidOperationException(nameof(fallback))
return cacheFallback switch {
ECacheFallback.DefaultForType => (false, default(T?)),
ECacheFallback.FailedNow => (false, result),
ECacheFallback.SuccessPreviously => (false, InitializedValue),
_ => throw new InvalidOperationException(nameof(cacheFallback))
};
}
@@ -97,15 +97,8 @@ public sealed class ArchiCacheable<T> : IDisposable {
}
InitializedAt = DateTime.MinValue;
InitializedValue = default(T?);
} finally {
InitSemaphore.Release();
}
}
public enum EFallback : byte {
DefaultForType,
FailedNow,
SuccessPreviously
}
}

View File

@@ -0,0 +1,28 @@
// _ _ _ ____ _ _____
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
// |
// Copyright 2015-2023 Łukasz "JustArchi" Domeradzki
// Contact: JustArchi@JustArchi.net
// |
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// |
// http://www.apache.org/licenses/LICENSE-2.0
// |
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace ArchiSteamFarm.Helpers;
public enum ECacheFallback : byte {
DefaultForType,
FailedNow,
SuccessPreviously
}