Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

DefaultCacheKeyGenerator.cs 1.3KB

12345678910111213141516171819202122232425262728293031323334
  1. using System.Linq;
  2. using System.Net.Http;
  3. using System.Net.Http.Headers;
  4. using System.Web;
  5. using System.Web.Http.Controllers;
  6. using iiie.CacheControl.Business.OutputCache;
  7. using Newtonsoft.Json;
  8. namespace iiie.CacheControl.Business.CacheKey
  9. {
  10. public class DefaultCacheKeyGenerator : ICacheKeyGenerator
  11. {
  12. public virtual string MakeCacheKey(HttpActionContext context, MediaTypeHeaderValue mediaType,
  13. OutputCacheType cacheType, bool excludeQueryString = false, bool excludePost = false)
  14. {
  15. string parameters = context.Request.Method.Method + "-" + context.Request.RequestUri.AbsolutePath;
  16. if (!excludeQueryString)
  17. {
  18. var pairs = context.Request.GetQueryNameValuePairs().OrderBy(x => x.Key);
  19. parameters += "?" + string.Join("&", pairs.Select(x => HttpUtility.UrlEncode(x.Key)
  20. + "=" + HttpUtility.UrlEncode(x.Value)));
  21. }
  22. if (!excludePost)
  23. {
  24. parameters += "?" + string.Join("&", context.ActionArguments.Select(x => HttpUtility.UrlEncode(x.Key)
  25. + "=" + HttpUtility.UrlEncode(JsonConvert.SerializeObject(x.Value))));
  26. }
  27. var cachekey = string.Format("{0}:{1}", parameters, mediaType.MediaType);
  28. return cachekey;
  29. }
  30. }
  31. }