Selaa lähdekoodia

[CacheControl] Fixed test; added argument for cache output

feature/package-cache-control
Robin Thoni 9 vuotta sitten
vanhempi
commit
98ad2f5657

+ 1
- 0
CacheControl-test/CacheControl-test.csproj Näytä tiedosto

@@ -155,6 +155,7 @@
155 155
     <Compile Include="Areas\HelpPage\SampleGeneration\TextSample.cs" />
156 156
     <Compile Include="Areas\HelpPage\XmlDocumentationProvider.cs" />
157 157
     <Compile Include="Controllers\HomeController.cs" />
158
+    <Compile Include="Controllers\MyCacheOutputAttribute.cs" />
158 159
     <Compile Include="Controllers\ValuesController.cs" />
159 160
     <Compile Include="Global.asax.cs">
160 161
       <DependentUpon>Global.asax</DependentUpon>

+ 15
- 0
CacheControl-test/Controllers/MyCacheOutputAttribute.cs Näytä tiedosto

@@ -0,0 +1,15 @@
1
+using System.IO;
2
+using iiie.CacheControl.Business.Attributes;
3
+using iiie.CacheControl.Business.OutputCache;
4
+
5
+namespace CacheControl_test.Controllers
6
+{
7
+    public class MyCacheOutputAttribute : TimeCacheControlAttribute
8
+    {
9
+        public MyCacheOutputAttribute(int seconds) : base(seconds)
10
+        {
11
+            CacheOutputData = Path.Combine(Path.GetTempPath(), "cache-control-test");
12
+            CacheType = OutputCacheType.File;
13
+        }
14
+    }
15
+}

+ 1
- 3
CacheControl-test/Controllers/ValuesController.cs Näytä tiedosto

@@ -1,7 +1,5 @@
1 1
 using System.Collections.Generic;
2 2
 using System.Web.Http;
3
-using iiie.CacheControl.Business.Attributes;
4
-using iiie.CacheControl.Business.OutputCache;
5 3
 
6 4
 namespace CacheControl_test.Controllers
7 5
 {
@@ -14,7 +12,7 @@ namespace CacheControl_test.Controllers
14 12
         }
15 13
 
16 14
         // GET api/values/5
17
-        [TimeCacheControl(60, true, false, OutputCacheType.File)]
15
+        [MyCacheOutput(60)]
18 16
         public string Get(int id)
19 17
         {
20 18
             return "value";

+ 6
- 1
CacheControl/Business/Attributes/CacheControlAttribute.cs Näytä tiedosto

@@ -27,6 +27,11 @@ namespace iiie.CacheControl.Attributes
27 27
         /// </summary>
28 28
         protected bool MustRevalidate { get; set; }
29 29
 
30
+        /// <summary>
31
+        /// Data used by OutputCache
32
+        /// </summary>
33
+        protected object CacheOutputData { get; set; }
34
+
30 35
         /// <summary>
31 36
         /// Indicates if the query string must be used to control cache
32 37
         /// </summary>
@@ -45,7 +50,7 @@ namespace iiie.CacheControl.Attributes
45 50
 
46 51
         protected void EnsureCache(HttpConfiguration config, HttpRequestMessage req)
47 52
         {
48
-            _webCache = config.CacheOutputConfiguration(CacheType).GetCacheOutputProvider(req);
53
+            _webCache = config.CacheOutputConfiguration(CacheType).GetCacheOutputProvider(req, CacheOutputData);
49 54
         }
50 55
 
51 56
         protected abstract bool IsValid(CacheDbo data);

+ 1
- 9
CacheControl/Business/Attributes/TimeCacheControlAttribute.cs Näytä tiedosto

@@ -18,17 +18,9 @@ namespace iiie.CacheControl.Business.Attributes
18 18
         /// <summary>
19 19
         /// Contruct a cache control based on time
20 20
         /// </summary>
21
-        /// <param name="seconds">The number of seconds the cache is valid</param>
22
-        /// <param name="mustRevalidate">Indicates if the client can reuse cached data without asking origin server</param>
23
-        /// <param name="excludeQueryStringFromCacheKey">Indicates if the query string must be used to control cache</param>
24
-        /// <param name="cacheType">Define the cache type used to store cache</param>
25
-        public TimeCacheControlAttribute(int seconds, bool mustRevalidate = true,
26
-            bool excludeQueryStringFromCacheKey = false, OutputCacheType cacheType = OutputCacheType.Memory)
21
+        public TimeCacheControlAttribute(int seconds)
27 22
         {
28 23
             Seconds = seconds;
29
-            MustRevalidate = mustRevalidate;
30
-            ExcludeQueryStringFromCacheKey = excludeQueryStringFromCacheKey;
31
-            CacheType = cacheType;
32 24
         }
33 25
 
34 26
         /// <summary>

+ 2
- 2
CacheControl/Business/HttpExtensions/CacheOutputConfiguration.cs Näytä tiedosto

@@ -89,7 +89,7 @@ namespace iiie.CacheControl.Business.HttpExtensions
89 89
                 ?? new DefaultCacheKeyGenerator();
90 90
         }
91 91
 
92
-        public IOutputCache GetCacheOutputProvider(HttpRequestMessage request)
92
+        public IOutputCache GetCacheOutputProvider(HttpRequestMessage request, object cacheOutputData)
93 93
         {
94 94
             object cache;
95 95
             _configuration.Properties.TryGetValue(typeof(IOutputCache), out cache);
@@ -100,7 +100,7 @@ namespace iiie.CacheControl.Business.HttpExtensions
100 100
             if (cacheOutputProvider == null)
101 101
             {
102 102
                 if (_cacheType == OutputCacheType.File)
103
-                    cacheOutputProvider = new FileOuputCache();
103
+                    cacheOutputProvider = new FileOuputCache(cacheOutputData as string);
104 104
                 else
105 105
                     cacheOutputProvider = new MemoryOutputCache();
106 106
             }

+ 4
- 2
CacheControl/Business/OutputCache/FileOuputCache.cs Näytä tiedosto

@@ -7,9 +7,11 @@ namespace iiie.CacheControl.Business.OutputCache
7 7
 {
8 8
     public class FileOuputCache : IOutputCache
9 9
     {
10
-        public string TempPath
10
+        private string TempPath { get; set; }
11
+
12
+        public FileOuputCache(string tempPath)
11 13
         {
12
-            get { return Path.Combine(Path.GetTempPath(), "co-planningCache"); }
14
+            TempPath = tempPath;
13 15
         }
14 16
 
15 17
         public string GetPath(string key)

Loading…
Peruuta
Tallenna