|
1 | 1 | using System.Collections.Concurrent;
|
2 | 2 |
|
3 |
| -namespace Ocelot.LoadBalancer.LoadBalancers |
| 3 | +namespace Ocelot.LoadBalancer.LoadBalancers; |
| 4 | + |
| 5 | +public class InMemoryStickySessionStorage : IStickySessionStorage |
4 | 6 | {
|
5 |
| - public class InMemoryStickySessionStorage : IStickySessionStorage |
| 7 | + private readonly ConcurrentDictionary<string, StickySession> _storage; |
| 8 | + |
| 9 | + public InMemoryStickySessionStorage() |
| 10 | + { |
| 11 | + _storage = new ConcurrentDictionary<string, StickySession>(); |
| 12 | + } |
| 13 | + |
| 14 | + public bool TryGetSession(string key, out StickySession session) |
| 15 | + { |
| 16 | + return _storage.TryGetValue(key, out session); |
| 17 | + } |
| 18 | + |
| 19 | + public StickySession GetSession(string key) |
| 20 | + { |
| 21 | + return _storage.TryGetValue(key, out var session) ? session : null; |
| 22 | + } |
| 23 | + |
| 24 | + public void SetSession(string key, StickySession session) |
| 25 | + { |
| 26 | + _storage[key] = session; |
| 27 | + } |
| 28 | + |
| 29 | + public bool TryRemove(string key, out StickySession session) |
| 30 | + { |
| 31 | + return _storage.TryRemove(key, out session); |
| 32 | + } |
| 33 | + |
| 34 | + public bool Contains(string key) |
6 | 35 | {
|
7 |
| - private readonly ConcurrentDictionary<string, StickySession> _storage; |
8 |
| - |
9 |
| - public InMemoryStickySessionStorage() |
10 |
| - { |
11 |
| - _storage = new ConcurrentDictionary<string, StickySession>(); |
12 |
| - } |
13 |
| - |
14 |
| - public bool TryGetSession(string key, out StickySession session) |
15 |
| - { |
16 |
| - return _storage.TryGetValue(key, out session); |
17 |
| - } |
18 |
| - |
19 |
| - public StickySession GetSession(string key) |
20 |
| - { |
21 |
| - return _storage.TryGetValue(key, out var session) ? session : null; |
22 |
| - } |
23 |
| - |
24 |
| - public void SetSession(string key, StickySession session) |
25 |
| - { |
26 |
| - _storage[key] = session; |
27 |
| - } |
28 |
| - |
29 |
| - public bool TryRemove(string key, out StickySession session) |
30 |
| - { |
31 |
| - return _storage.TryRemove(key, out session); |
32 |
| - } |
33 |
| - |
34 |
| - public bool Contains(string key) |
35 |
| - { |
36 |
| - return _storage.ContainsKey(key); |
37 |
| - } |
| 36 | + return _storage.ContainsKey(key); |
38 | 37 | }
|
39 | 38 | }
|
0 commit comments