CachedVaryBy.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. using System.Collections;
  12. namespace System.Web.Caching {
  13. internal class CachedVaryBy {
  14. private string[] prms;
  15. private string[] headers;
  16. private string custom;
  17. private string key;
  18. private ArrayList item_list;
  19. internal CachedVaryBy (HttpCachePolicy policy, string key)
  20. {
  21. prms = policy.VaryByParams.GetParamNames ();
  22. headers = policy.VaryByHeaders.GetHeaderNames ();
  23. custom = policy.GetVaryByCustom ();
  24. this.key = key;
  25. item_list = new ArrayList ();
  26. }
  27. internal ArrayList ItemList {
  28. get { return item_list; }
  29. }
  30. internal string Key {
  31. get { return key; }
  32. }
  33. internal string CreateKey (string file_path, HttpContext context)
  34. {
  35. StringBuilder builder = new StringBuilder ();
  36. HttpApplication app = context.ApplicationInstance;
  37. HttpRequest request = context.Request;
  38. builder.Append ("CachedRawResponse\n");
  39. builder.Append (file_path);
  40. builder.Append ('\n');
  41. builder.Append ("METHOD:" + request.HttpMethod);
  42. builder.Append ('\n');
  43. if (prms != null) {
  44. for (int i=0; i<prms.Length; i++) {
  45. if (request.Params [prms [i]] == null)
  46. continue;
  47. builder.Append ("VP:");
  48. builder.Append (prms [i]);
  49. builder.Append ('=');
  50. builder.Append (request.Params [prms [i]]);
  51. builder.Append ('\n');
  52. }
  53. }
  54. if (headers != null) {
  55. for (int i=0; i<headers.Length; i++) {
  56. builder.Append ("VH:");
  57. builder.Append (headers [i]);
  58. builder.Append ('=');
  59. builder.Append (request.Headers [headers [i]]);
  60. builder.Append ('\n');
  61. }
  62. }
  63. if (custom != null) {
  64. string s = app.GetVaryByCustomString (context, custom);
  65. builder.Append ("VC:");
  66. builder.Append (custom);
  67. builder.Append ('=');
  68. builder.Append (s != null ? s : "__null__");
  69. builder.Append ('\n');
  70. }
  71. return builder.ToString ();
  72. }
  73. }
  74. }