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