Skip to content

Commit 37ab39a

Browse files
committed
Merge pull request #139 from filipw/bugfix/controllername-cachekey
globally apply the change from ControllerName -> ControllerType.FullName
2 parents db44627 + bcdf210 commit 37ab39a

13 files changed

Lines changed: 102 additions & 102 deletions

src/WebApi.OutputCache.V2/AutoInvalidateCacheOutputAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public override void OnActionExecuted(HttpActionExecutedContext actionExecutedCo
3232

3333
foreach (var action in actions)
3434
{
35-
var key = config.CacheOutputConfiguration().MakeBaseCachekey(controller.ControllerName, action);
35+
var key = config.CacheOutputConfiguration().MakeBaseCachekey(controller.ControllerType.FullName, action);
3636
if (WebApiCache.Contains(key))
3737
{
3838
WebApiCache.RemoveStartsWith(key);

src/WebApi.OutputCache.V2/CacheOutputAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public override async Task OnActionExecutedAsync(HttpActionExecutedContext actio
204204

205205
if (responseContent != null)
206206
{
207-
var baseKey = config.MakeBaseCachekey(actionExecutedContext.ActionContext.ControllerContext.ControllerDescriptor.ControllerName, actionExecutedContext.ActionContext.ActionDescriptor.ActionName);
207+
var baseKey = config.MakeBaseCachekey(actionExecutedContext.ActionContext.ControllerContext.ControllerDescriptor.ControllerType.FullName, actionExecutedContext.ActionContext.ActionDescriptor.ActionName);
208208
var contentType = responseContent.Headers.ContentType;
209209
string etag = actionExecutedContext.Response.Headers.ETag.Tag;
210210
//ConfigureAwait false to avoid deadlocks

src/WebApi.OutputCache.V2/CacheOutputConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public string MakeBaseCachekey<T, U>(Expression<Func<T, U>> expression)
5454
}
5555
}
5656

57-
return string.Format("{0}-{1}", typeof(T).Name.Replace("Controller",string.Empty).ToLower(), methodName.ToLower());
57+
return string.Format("{0}-{1}", typeof(T).FullName.ToLower(), methodName.ToLower());
5858
}
5959

6060
private static ICacheKeyGenerator TryActivateCacheKeyGenerator(Type generatorType)

src/WebApi.OutputCache.V2/DefaultCacheKeyGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class DefaultCacheKeyGenerator : ICacheKeyGenerator
1313
{
1414
public virtual string MakeCacheKey(HttpActionContext context, MediaTypeHeaderValue mediaType, bool excludeQueryString = false)
1515
{
16-
var controller = context.ControllerContext.ControllerDescriptor.ControllerName;
16+
var controller = context.ControllerContext.ControllerDescriptor.ControllerType.FullName;
1717
var action = context.ActionDescriptor.ActionName;
1818
var key = context.Request.GetConfiguration().CacheOutputConfiguration().MakeBaseCachekey(controller, action);
1919
var actionParameters = context.ActionArguments.Where(x => x.Value != null).Select(x => x.Key + "=" + GetValue(x.Value));

src/WebApi.OutputCache.V2/InvalidateCacheOutputAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public InvalidateCacheOutputAttribute(string methodName, Type type = null)
2424
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
2525
{
2626
if (actionExecutedContext.Response != null && !actionExecutedContext.Response.IsSuccessStatusCode) return;
27-
_controller = _controller ?? actionExecutedContext.ActionContext.ControllerContext.ControllerDescriptor.ControllerName;
27+
_controller = _controller ?? actionExecutedContext.ActionContext.ControllerContext.ControllerDescriptor.ControllerType.FullName;
2828

2929
var config = actionExecutedContext.Request.GetConfiguration();
3030
EnsureCache(config, actionExecutedContext.Request);

test/WebApi.OutputCache.V2.Tests/CacheKeyGeneratorRegistrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void selected_generator_with_internal_registration_is_used()
8989
var client = new HttpClient(_server);
9090
var result = client.GetAsync(_url + "cachekey/get_internalregistered").Result;
9191

92-
_cache.Verify(s => s.Add(It.Is<string>(x => x == "internal"), It.IsAny<byte[]>(), It.Is<DateTimeOffset>(x => x <= DateTime.Now.AddSeconds(100)), It.Is<string>(x => x == "cachekey-get_internalregistered")), Times.Once());
92+
_cache.Verify(s => s.Add(It.Is<string>(x => x == "internal"), It.IsAny<byte[]>(), It.Is<DateTimeOffset>(x => x <= DateTime.Now.AddSeconds(100)), It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.cachekeycontroller-get_internalregistered")), Times.Once());
9393
}
9494

9595
[Test]

test/WebApi.OutputCache.V2.Tests/CacheKeyGeneratorTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public void custom_default_cache_key_generator_called_and_key_used()
6666
var result = client.GetAsync(_url + "sample/Get_c100_s100").Result;
6767

6868
_cache.Verify(s => s.Contains(It.Is<string>(x => x == "keykeykey")), Times.Exactly(2));
69-
_cache.Verify(s => s.Add(It.Is<string>(x => x == "keykeykey"), It.IsAny<byte[]>(), It.Is<DateTimeOffset>(x => x <= DateTime.Now.AddSeconds(100)), It.Is<string>(x => x == "sample-get_c100_s100")), Times.Once());
70-
_cache.Verify(s => s.Add(It.Is<string>(x => x == "keykeykey:response-ct"), It.IsAny<object>(), It.Is<DateTimeOffset>(x => x <= DateTime.Now.AddSeconds(100)), It.Is<string>(x => x == "sample-get_c100_s100")), Times.Once());
69+
_cache.Verify(s => s.Add(It.Is<string>(x => x == "keykeykey"), It.IsAny<byte[]>(), It.Is<DateTimeOffset>(x => x <= DateTime.Now.AddSeconds(100)), It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.samplecontroller-get_c100_s100")), Times.Once());
70+
_cache.Verify(s => s.Add(It.Is<string>(x => x == "keykeykey:response-ct"), It.IsAny<object>(), It.Is<DateTimeOffset>(x => x <= DateTime.Now.AddSeconds(100)), It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.samplecontroller-get_c100_s100")), Times.Once());
7171

7272
_keyGeneratorA.VerifyAll();
7373
}
@@ -79,8 +79,8 @@ public void custom_cache_key_generator_called()
7979
var result = client.GetAsync(_url + "cachekey/get_custom_key").Result;
8080

8181
_cache.Verify(s => s.Contains(It.Is<string>(x => x == "custom_key")), Times.Exactly(2));
82-
_cache.Verify(s => s.Add(It.Is<string>(x => x == "custom_key"), It.IsAny<byte[]>(), It.Is<DateTimeOffset>(x => x <= DateTime.Now.AddSeconds(100)), It.Is<string>(x => x == "cachekey-get_custom_key")), Times.Once());
83-
_cache.Verify(s => s.Add(It.Is<string>(x => x == "custom_key:response-ct"), It.IsAny<object>(), It.Is<DateTimeOffset>(x => x <= DateTime.Now.AddSeconds(100)), It.Is<string>(x => x == "cachekey-get_custom_key")), Times.Once());
82+
_cache.Verify(s => s.Add(It.Is<string>(x => x == "custom_key"), It.IsAny<byte[]>(), It.Is<DateTimeOffset>(x => x <= DateTime.Now.AddSeconds(100)), It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.cachekeycontroller-get_custom_key")), Times.Once());
83+
_cache.Verify(s => s.Add(It.Is<string>(x => x == "custom_key:response-ct"), It.IsAny<object>(), It.Is<DateTimeOffset>(x => x <= DateTime.Now.AddSeconds(100)), It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.cachekeycontroller-get_custom_key")), Times.Once());
8484
}
8585
}
8686
}

test/WebApi.OutputCache.V2.Tests/ConfigurationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public void cache_singleton_in_pipeline()
3333
var client = new HttpClient(_server);
3434
var result = client.GetAsync(_url + "Get_c100_s100").Result;
3535

36-
_cache.Verify(s => s.Contains(It.Is<string>(x => x == "sample-get_c100_s100:application/json; charset=utf-8")), Times.Exactly(2));
36+
_cache.Verify(s => s.Contains(It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.samplecontroller-get_c100_s100:application/json; charset=utf-8")), Times.Exactly(2));
3737

3838
var result2 = client.GetAsync(_url + "Get_c100_s100").Result;
39-
_cache.Verify(s => s.Contains(It.Is<string>(x => x == "sample-get_c100_s100:application/json; charset=utf-8")), Times.Exactly(4));
39+
_cache.Verify(s => s.Contains(It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.samplecontroller-get_c100_s100:application/json; charset=utf-8")), Times.Exactly(4));
4040

4141
_server.Dispose();
4242
}

test/WebApi.OutputCache.V2.Tests/ConnegTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ public void subsequent_xml_request_is_not_cached()
4242
var client = new HttpClient(_server);
4343
var result = client.GetAsync(_url + "Get_c100_s100").Result;
4444

45-
_cache.Verify(s => s.Contains(It.Is<string>(x => x == "sample-get_c100_s100:application/json; charset=utf-8")), Times.Exactly(2));
46-
_cache.Verify(s => s.Add(It.Is<string>(x => x == "sample-get_c100_s100:application/json; charset=utf-8"), It.IsAny<object>(), It.Is<DateTimeOffset>(x => x < DateTime.Now.AddSeconds(100)), It.Is<string>(x => x == "sample-get_c100_s100")), Times.Once());
45+
_cache.Verify(s => s.Contains(It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.samplecontroller-get_c100_s100:application/json; charset=utf-8")), Times.Exactly(2));
46+
_cache.Verify(s => s.Add(It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.samplecontroller-get_c100_s100:application/json; charset=utf-8"), It.IsAny<object>(), It.Is<DateTimeOffset>(x => x < DateTime.Now.AddSeconds(100)), It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.samplecontroller-get_c100_s100")), Times.Once());
4747

4848
var req = new HttpRequestMessage(HttpMethod.Get, _url + "Get_c100_s100");
4949
req.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));
5050

5151
var result2 = client.SendAsync(req).Result;
52-
_cache.Verify(s => s.Contains(It.Is<string>(x => x == "sample-get_c100_s100:text/xml; charset=utf-8")), Times.Exactly(2));
53-
_cache.Verify(s => s.Add(It.Is<string>(x => x == "sample-get_c100_s100:text/xml; charset=utf-8"), It.IsAny<object>(), It.Is<DateTimeOffset>(x => x < DateTime.Now.AddSeconds(100)), It.Is<string>(x => x == "sample-get_c100_s100")), Times.Once());
52+
_cache.Verify(s => s.Contains(It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.samplecontroller-get_c100_s100:text/xml; charset=utf-8")), Times.Exactly(2));
53+
_cache.Verify(s => s.Add(It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.samplecontroller-get_c100_s100:text/xml; charset=utf-8"), It.IsAny<object>(), It.Is<DateTimeOffset>(x => x < DateTime.Now.AddSeconds(100)), It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.samplecontroller-get_c100_s100")), Times.Once());
5454

5555
}
5656

test/WebApi.OutputCache.V2.Tests/InlineInvalidateTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void inline_call_to_invalidate_is_correct()
4444

4545
var result = client.PostAsync(_url + "Post", new StringContent(string.Empty)).Result;
4646

47-
_cache.Verify(s => s.RemoveStartsWith(It.Is<string>(x => x == "inlineinvalidate-get_c100_s100")), Times.Exactly(1));
47+
_cache.Verify(s => s.RemoveStartsWith(It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.inlineinvalidatecontroller-get_c100_s100")), Times.Exactly(1));
4848
}
4949

5050
[Test]
@@ -53,7 +53,7 @@ public void inline_call_to_invalidate_using_expression_tree_is_correct()
5353
var client = new HttpClient(_server);
5454
var result = client.PutAsync(_url + "Put", new StringContent(string.Empty)).Result;
5555

56-
_cache.Verify(s => s.RemoveStartsWith(It.Is<string>(x => x == "inlineinvalidate-get_c100_s100")), Times.Exactly(1));
56+
_cache.Verify(s => s.RemoveStartsWith(It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.inlineinvalidatecontroller-get_c100_s100")), Times.Exactly(1));
5757
}
5858

5959
[Test]
@@ -62,7 +62,7 @@ public void inline_call_to_invalidate_using_expression_tree_with_param_is_correc
6262
var client = new HttpClient(_server);
6363
var result = client.DeleteAsync(_url + "Delete_parameterized").Result;
6464

65-
_cache.Verify(s => s.RemoveStartsWith(It.Is<string>(x => x == "inlineinvalidate-get_c100_s100_with_param")), Times.Exactly(1));
65+
_cache.Verify(s => s.RemoveStartsWith(It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.inlineinvalidatecontroller-get_c100_s100_with_param")), Times.Exactly(1));
6666
}
6767

6868
[Test]
@@ -71,7 +71,7 @@ public void inline_call_to_invalidate_using_expression_tree_with_custom_action_n
7171
var client = new HttpClient(_server);
7272
var result = client.DeleteAsync(_url + "Delete_non_standard_name").Result;
7373

74-
_cache.Verify(s => s.RemoveStartsWith(It.Is<string>(x => x == "inlineinvalidate-getbyid")), Times.Exactly(1));
74+
_cache.Verify(s => s.RemoveStartsWith(It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.inlineinvalidatecontroller-getbyid")), Times.Exactly(1));
7575
}
7676

7777
[TearDown]

0 commit comments

Comments
 (0)