CachedVaryBy.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Text;
  31. using System.Collections;
  32. namespace System.Web.Caching {
  33. internal class CachedVaryBy {
  34. private string[] prms;
  35. private string[] headers;
  36. private string custom;
  37. private string key;
  38. private ArrayList item_list;
  39. internal CachedVaryBy (HttpCachePolicy policy, string key)
  40. {
  41. prms = policy.VaryByParams.GetParamNames ();
  42. headers = policy.VaryByHeaders.GetHeaderNames ();
  43. custom = policy.GetVaryByCustom ();
  44. this.key = key;
  45. item_list = new ArrayList ();
  46. }
  47. internal ArrayList ItemList {
  48. get { return item_list; }
  49. }
  50. internal string Key {
  51. get { return key; }
  52. }
  53. internal string CreateKey (string file_path, HttpContext context)
  54. {
  55. StringBuilder builder = new StringBuilder ();
  56. HttpApplication app = context.ApplicationInstance;
  57. HttpRequest request = context.Request;
  58. builder.Append ("CachedRawResponse\n");
  59. builder.Append (file_path);
  60. builder.Append ('\n');
  61. builder.Append ("METHOD:" + request.HttpMethod);
  62. builder.Append ('\n');
  63. if (prms != null) {
  64. for (int i=0; i<prms.Length; i++) {
  65. if (request.Params [prms [i]] == null)
  66. continue;
  67. builder.Append ("VP:");
  68. builder.Append (prms [i]);
  69. builder.Append ('=');
  70. builder.Append (request.Params [prms [i]]);
  71. builder.Append ('\n');
  72. }
  73. }
  74. if (headers != null) {
  75. for (int i=0; i<headers.Length; i++) {
  76. builder.Append ("VH:");
  77. builder.Append (headers [i]);
  78. builder.Append ('=');
  79. builder.Append (request.Headers [headers [i]]);
  80. builder.Append ('\n');
  81. }
  82. }
  83. if (custom != null) {
  84. string s = app.GetVaryByCustomString (context, custom);
  85. builder.Append ("VC:");
  86. builder.Append (custom);
  87. builder.Append ('=');
  88. builder.Append (s != null ? s : "__null__");
  89. builder.Append ('\n');
  90. }
  91. return builder.ToString ();
  92. }
  93. }
  94. }