Code cleanup

This commit is contained in:
Andriy
2023-07-29 15:03:45 +03:00
parent 5e4183acfa
commit a24332370d
36 changed files with 46 additions and 111 deletions
+7 -9
View File
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using SQLitePCL;
namespace Kruzya.TelegramBot.Core.Cache
{
@@ -32,7 +30,7 @@ namespace Kruzya.TelegramBot.Core.Cache
/// <summary>
///
/// </summary>
private Dictionary<TKey, CacheEntry<TValue>> dict = new Dictionary<TKey, CacheEntry<TValue>>();
private readonly Dictionary<TKey, CacheEntry<TValue>> _dict = new();
/// <summary>
/// The TTL for all entries if not set.
@@ -51,20 +49,20 @@ namespace Kruzya.TelegramBot.Core.Cache
public bool TryGetValue(TKey key, out TValue value)
{
value = default;
if (!dict.ContainsKey(key))
if (!_dict.ContainsKey(key))
{
return false;
}
CacheEntry<TValue> temp;
if (!dict.TryGetValue(key, out temp))
if (!_dict.TryGetValue(key, out temp))
{
return false;
}
if (temp.IsExpired())
{
dict.Remove(key);
_dict.Remove(key);
return false;
}
@@ -90,12 +88,12 @@ namespace Kruzya.TelegramBot.Core.Cache
public void SetValue(TKey key, TValue value, int timeToLive)
{
if (dict.ContainsKey(key))
if (_dict.ContainsKey(key))
{
dict.Remove(key);
_dict.Remove(key);
}
dict.Add(key, new CacheEntry<TValue>()
_dict.Add(key, new CacheEntry<TValue>()
{
Created = DateTime.Now,
ExpiresAt = timeToLive,