mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Code cleanup
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user