Browse Source

[CacheControl] Fixed test; added argument for cache output

feature/package-cache-control
Robin Thoni 9 years ago
parent
commit
98ad2f5657

+ 1
- 0
CacheControl-test/CacheControl-test.csproj View File

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

+ 15
- 0
CacheControl-test/Controllers/MyCacheOutputAttribute.cs View File

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 View File

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

+ 6
- 1
CacheControl/Business/Attributes/CacheControlAttribute.cs View File

27
         /// </summary>
27
         /// </summary>
28
         protected bool MustRevalidate { get; set; }
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
         /// <summary>
35
         /// <summary>
31
         /// Indicates if the query string must be used to control cache
36
         /// Indicates if the query string must be used to control cache
32
         /// </summary>
37
         /// </summary>
45
 
50
 
46
         protected void EnsureCache(HttpConfiguration config, HttpRequestMessage req)
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
         protected abstract bool IsValid(CacheDbo data);
56
         protected abstract bool IsValid(CacheDbo data);

+ 1
- 9
CacheControl/Business/Attributes/TimeCacheControlAttribute.cs View File

18
         /// <summary>
18
         /// <summary>
19
         /// Contruct a cache control based on time
19
         /// Contruct a cache control based on time
20
         /// </summary>
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
             Seconds = seconds;
23
             Seconds = seconds;
29
-            MustRevalidate = mustRevalidate;
30
-            ExcludeQueryStringFromCacheKey = excludeQueryStringFromCacheKey;
31
-            CacheType = cacheType;
32
         }
24
         }
33
 
25
 
34
         /// <summary>
26
         /// <summary>

+ 2
- 2
CacheControl/Business/HttpExtensions/CacheOutputConfiguration.cs View File

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

+ 4
- 2
CacheControl/Business/OutputCache/FileOuputCache.cs View File

7
 {
7
 {
8
     public class FileOuputCache : IOutputCache
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
         public string GetPath(string key)
17
         public string GetPath(string key)

Loading…
Cancel
Save