2
0

HttpRequestCachePolicy.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // System.Net.Cache.HttpRequestCachePolicy.cs
  3. //
  4. // Authors:
  5. // Tim Coleman ([email protected])
  6. //
  7. // Copyright (C) Tim Coleman, 2004
  8. // (c) 2004 Novell, Inc. (http://www.novell.com)
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. #if NET_2_0
  31. using System;
  32. namespace System.Net.Cache
  33. {
  34. public sealed class HttpRequestCachePolicy : RequestCachePolicy
  35. {
  36. #region Fields
  37. DateTime cacheSyncDate;
  38. HttpRequestCacheLevel level = HttpRequestCacheLevel.Default;
  39. TimeSpan maxAge;
  40. TimeSpan maxStale;
  41. TimeSpan minFresh;
  42. #endregion // Fields
  43. #region Constructors
  44. public HttpRequestCachePolicy ()
  45. {
  46. }
  47. public HttpRequestCachePolicy (DateTime cacheSyncDate)
  48. {
  49. this.cacheSyncDate = cacheSyncDate;
  50. }
  51. public HttpRequestCachePolicy (HttpRequestCacheLevel level)
  52. {
  53. this.level = level;
  54. }
  55. public HttpRequestCachePolicy (HttpCacheAgeControl cacheAgeControl, TimeSpan ageOrFreshOrStale)
  56. {
  57. switch (cacheAgeControl) {
  58. case HttpCacheAgeControl.MaxAge:
  59. maxAge = ageOrFreshOrStale;
  60. break;
  61. case HttpCacheAgeControl.MaxStale:
  62. maxStale = ageOrFreshOrStale;
  63. break;
  64. case HttpCacheAgeControl.MinFresh:
  65. minFresh = ageOrFreshOrStale;
  66. break;
  67. default:
  68. throw new ArgumentException ("ageOrFreshOrStale");
  69. }
  70. }
  71. public HttpRequestCachePolicy (HttpCacheAgeControl cacheAgeControl, TimeSpan maxAge, TimeSpan freshOrStale)
  72. {
  73. this.maxAge = maxAge;
  74. switch (cacheAgeControl) {
  75. case HttpCacheAgeControl.MaxStale:
  76. maxStale = freshOrStale;
  77. break;
  78. case HttpCacheAgeControl.MinFresh:
  79. minFresh = freshOrStale;
  80. break;
  81. default:
  82. throw new ArgumentException ("freshOrStale");
  83. }
  84. }
  85. public HttpRequestCachePolicy (HttpCacheAgeControl cacheAgeControl, TimeSpan maxAge, TimeSpan freshOrStale, DateTime cacheSyncDate)
  86. : this (cacheAgeControl, maxAge, freshOrStale)
  87. {
  88. this.cacheSyncDate = cacheSyncDate;
  89. }
  90. #endregion // Constructors
  91. #region Properties
  92. public DateTime CacheSyncDate {
  93. get { return cacheSyncDate; }
  94. }
  95. public new HttpRequestCacheLevel Level {
  96. get { return level; }
  97. }
  98. public TimeSpan MaxAge {
  99. get { return maxAge; }
  100. }
  101. public TimeSpan MaxStale {
  102. get { return maxStale; }
  103. }
  104. public TimeSpan MinFresh {
  105. get { return minFresh; }
  106. }
  107. #endregion // Properties
  108. #region Methods
  109. [MonoTODO]
  110. public override string ToString ()
  111. {
  112. throw new NotImplementedException ();
  113. }
  114. #endregion // Methods
  115. }
  116. }
  117. #endif