CachedVaryBy.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // System.Web.Caching.CachedVaryBy
  3. //
  4. // Author(s):
  5. // Jackson Harper ([email protected])
  6. //
  7. // (C) 2003 Novell, Inc (http://www.novell.com)
  8. //
  9. using System;
  10. using System.Text;
  11. namespace System.Web.Caching {
  12. internal class CachedVaryBy {
  13. private string[] prms;
  14. private string[] headers;
  15. private string custom;
  16. internal CachedVaryBy (HttpCachePolicy policy)
  17. {
  18. prms = policy.VaryByParams.GetParamNames ();
  19. headers = policy.VaryByHeaders.GetHeaderNames ();
  20. custom = policy.GetVaryByCustom ();
  21. }
  22. internal string CreateKey (string file_path, HttpContext context)
  23. {
  24. StringBuilder builder = new StringBuilder ();
  25. HttpApplication app = context.ApplicationInstance;
  26. HttpRequest request = context.Request;
  27. builder.Append ("CachedRawResponse\n");
  28. builder.Append (file_path);
  29. builder.Append ('\n');
  30. builder.Append ("METHOD:" + request.HttpMethod);
  31. builder.Append ('\n');
  32. if (prms != null) {
  33. for (int i=0; i<prms.Length; i++) {
  34. if (request.Params [prms [i]] == null)
  35. continue;
  36. builder.Append ("VP:");
  37. builder.Append (prms [i]);
  38. builder.Append ('=');
  39. builder.Append (request.Params [prms [i]]);
  40. builder.Append ('\n');
  41. }
  42. }
  43. if (headers != null) {
  44. for (int i=0; i<headers.Length; i++) {
  45. builder.Append ("VH:");
  46. builder.Append (headers [i]);
  47. builder.Append ('=');
  48. builder.Append (request.Headers [headers [i]]);
  49. builder.Append ('\n');
  50. }
  51. }
  52. if (custom != null) {
  53. string s = app.GetVaryByCustomString (context, custom);
  54. builder.Append ("VC:");
  55. builder.Append (custom);
  56. builder.Append ('=');
  57. builder.Append (s != null ? s : "__null__");
  58. builder.Append ('\n');
  59. }
  60. return builder.ToString ();
  61. }
  62. }
  63. }