-
Notifications
You must be signed in to change notification settings - Fork 3
/
CarCache.cs
32 lines (28 loc) · 1.05 KB
/
CarCache.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
using Microsoft.Azure.ServiceBus;
using Microsoft.Azure.ServiceBus.Management;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SynchronizedCacheExample
{
public interface ICarCache : ISynchronizedCache<Car, CarType>
{
}
public class CarCache : SynchronizedCache<Car, CarType>, ICarCache
{
public CarCache(ManagementClient serviceBusManagementClient, ITopicClient serviceBusTopicClient) : base(serviceBusManagementClient, serviceBusTopicClient)
{
}
protected override string GetHashKey(CarType carType)
{
return $"{carType.Make}|{carType.Model}";
}
protected override async Task<Car> Load(CarType carType)
{
// Pretend you loaded this from a DB or some other async place
await Task.Delay(5000);
return new Car() { Make = carType.Make, Model = carType.Model, Horsepower = (DateTime.Now.Second * 100), MSRP = (decimal)(DateTime.Now.TimeOfDay.TotalMinutes + 10000) };
}
}
}