-
Notifications
You must be signed in to change notification settings - Fork 1
/
CacheManager.cs
30 lines (27 loc) · 1.02 KB
/
CacheManager.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
using Microsoft.AspNetCore.Http;
using System;
namespace AspNetCoreDashboardUseDifferentCaches
{
public class CacheManager {
const string SessionKey = "UniqueCacheParam";
protected IHttpContextAccessor HttpContextAccessor { get; }
public CacheManager(IHttpContextAccessor httpContextAccessor) {
this.HttpContextAccessor = httpContextAccessor;
}
public void ResetCache() {
HttpContextAccessor?.HttpContext?.Session?.SetString(SessionKey,Guid.NewGuid().ToString());
}
public Guid UniqueCacheParam {
get {
ISession session = HttpContextAccessor?.HttpContext?.Session;
if(session == null) {
return Guid.Empty;
} else {
if(string.IsNullOrEmpty(session.GetString(SessionKey)))
ResetCache();
return Guid.Parse(session.GetString(SessionKey));
}
}
}
}
}