|
1 | 1 | using System.Collections; |
2 | 2 | using System.Collections.Generic; |
3 | | -using System.Globalization; |
4 | 3 | using System.Linq; |
5 | 4 | using System.Net.Http; |
6 | 5 | using System.Net.Http.Headers; |
7 | | -using System.Text; |
8 | 6 | using System.Web.Http.Controllers; |
9 | 7 |
|
10 | 8 | namespace WebApi.OutputCache.V2 |
11 | 9 | { |
12 | 10 | public class DefaultCacheKeyGenerator : ICacheKeyGenerator |
13 | 11 | { |
14 | 12 | public virtual string MakeCacheKey(HttpActionContext context, MediaTypeHeaderValue mediaType, bool excludeQueryString = false) |
| 13 | + { |
| 14 | + var key = MakeBaseKey(context); |
| 15 | + var parameters = FormatParameters(context, excludeQueryString); |
| 16 | + |
| 17 | + return string.Format("{0}{1}:{2}", key, parameters, mediaType); |
| 18 | + } |
| 19 | + |
| 20 | + protected virtual string MakeBaseKey(HttpActionContext context) |
15 | 21 | { |
16 | 22 | var controller = context.ControllerContext.ControllerDescriptor.ControllerType.FullName; |
17 | 23 | var action = context.ActionDescriptor.ActionName; |
18 | | - var key = context.Request.GetConfiguration().CacheOutputConfiguration().MakeBaseCachekey(controller, action); |
| 24 | + return context.Request.GetConfiguration().CacheOutputConfiguration().MakeBaseCachekey(controller, action); |
| 25 | + } |
| 26 | + |
| 27 | + protected virtual string FormatParameters(HttpActionContext context, bool excludeQueryString) |
| 28 | + { |
19 | 29 | var actionParameters = context.ActionArguments.Where(x => x.Value != null).Select(x => x.Key + "=" + GetValue(x.Value)); |
20 | 30 |
|
21 | 31 | string parameters; |
@@ -45,9 +55,7 @@ public virtual string MakeCacheKey(HttpActionContext context, MediaTypeHeaderVal |
45 | 55 | } |
46 | 56 |
|
47 | 57 | if (parameters == "-") parameters = string.Empty; |
48 | | - |
49 | | - var cachekey = string.Format("{0}{1}:{2}", key, parameters, mediaType); |
50 | | - return cachekey; |
| 58 | + return parameters; |
51 | 59 | } |
52 | 60 |
|
53 | 61 | private string GetJsonpCallback(HttpRequestMessage request) |
|
0 commit comments