-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathPerUserCacheKeyGenerator.cs
More file actions
27 lines (24 loc) · 1.1 KB
/
PerUserCacheKeyGenerator.cs
File metadata and controls
27 lines (24 loc) · 1.1 KB
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
using System.Collections.Generic;
using System.Net.Http.Headers;
using System.Web.Http.Controllers;
namespace WebApi.OutputCache.V2
{
public class PerUserCacheKeyGenerator : DefaultCacheKeyGenerator
{
public override string MakeCacheKey(HttpActionContext context, MediaTypeHeaderValue mediaType, bool excludeQueryString, Dictionary<string, List<string>> headers)
{
var baseKey = MakeBaseKey(context);
var parameters = FormatParameters(context, excludeQueryString);
var userIdentity = FormatUserIdentity(context);
string custHeaders = GetCustomHeaders(headers);
if (!(string.IsNullOrEmpty(custHeaders)))
return string.Format("{0}{1}:{2}:{3}:{4}", baseKey, parameters, custHeaders, userIdentity, mediaType);
else
return string.Format("{0}{1}:{2}:{3}", baseKey, parameters, userIdentity, mediaType);
}
protected virtual string FormatUserIdentity(HttpActionContext context)
{
return context.RequestContext.Principal.Identity.Name.ToLower();
}
}
}