-
Notifications
You must be signed in to change notification settings - Fork 1
/
BankGetExchange.cs
47 lines (40 loc) · 1.35 KB
/
BankGetExchange.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Caching;
using System.Text;
using System.Threading.Tasks;
namespace InfoValutarShared
{
#pragma warning disable IDE1006 // Naming Styles
public interface BankGetExchange
#pragma warning restore IDE1006 // Naming Styles
{
public string Bank { get; }
Task<IEnumerable<ExchangeRates>> GetActualRates();
IEnumerable<ExchangeRates> TodayFromCache
{
get
{
string key = $"{this.Bank}_{DateTime.UtcNow.ToString("yyyyMMdd")}";
var mc = MemoryCache.Default;
if (mc.Contains(key))
return mc[key] as ExchangeRates[];
return null;
}
set
{
var now = DateTime.UtcNow;
var nextDay = now.Date.AddDays(1);
var offset = new DateTimeOffset(nextDay);
string key = $"{this.Bank}_{DateTime.UtcNow.ToString("yyyyMMdd")}";
var mc = MemoryCache.Default;
value = value
.Where(it => Math.Abs(it.Date.Subtract(now).TotalDays) < 1)
.ToArray();
if (value.Any())
mc.Set(key, value, offset);
}
}
}
}