-
Notifications
You must be signed in to change notification settings - Fork 3
/
AnimalCache.cs
42 lines (38 loc) · 1.31 KB
/
AnimalCache.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
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 IAnimalCache : ISynchronizedCache<Animal, string>
{
}
public class AnimalCache : SynchronizedCache<Animal, string>, IAnimalCache
{
public AnimalCache(ManagementClient serviceBusManagementClient, ITopicClient serviceBusTopicClient) : base(serviceBusManagementClient, serviceBusTopicClient)
{
}
protected override string GetHashKey(string key)
{
return key;
}
protected override async Task<Animal> Load(string key)
{
// Pretend you loaded this from a DB or some other async place
await Task.Delay(5000);
switch (key)
{
case "dog":
return new Animal() { Type = key, Name = "Rover", Color = "Brown" };
case "cat":
return new Animal() { Type = key, Name = "Mr. Puddy", Color = "White" };
case "fish":
return new Animal() { Type = key, Name = "Dory", Color = "Blue" };
default:
return null;
}
}
}
}