Skip to content

Commit

Permalink
fixing issue #22 and renaming policy attrib
Browse files Browse the repository at this point in the history
  • Loading branch information
aliostad committed Mar 18, 2013
1 parent 594ad61 commit 5bcd385
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ protected override CacheControlHeaderValue DoGetCacheControl(HttpRequestMessage


var actionDescriptor = httpActionSelector.SelectAction(controllerContext);
var cachePolicyAttribute = actionDescriptor.GetCustomAttributes<HttpCachePolicyAttribute>().FirstOrDefault();
var cachePolicyAttribute = actionDescriptor.GetCustomAttributes<HttpCacheControlPolicyAttribute>().FirstOrDefault();
if (cachePolicyAttribute != null)
return cachePolicyAttribute.CacheControl;

// now check controller
var controllerPolicy = controllerDescriptor.GetCustomAttributes<HttpCachePolicyAttribute>().FirstOrDefault();
var controllerPolicy = controllerDescriptor.GetCustomAttributes<HttpCacheControlPolicyAttribute>().FirstOrDefault();

return controllerPolicy == null ? null : controllerPolicy.CacheControl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@
namespace CacheCow.Server.CacheControlPolicy
{

public class CachePolicyHeader : CacheControlHeaderValue
{
}

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class HttpCachePolicyAttribute : Attribute
public class HttpCacheControlPolicyAttribute : Attribute
{

private readonly CacheControlHeaderValue _cacheControl;

/// <summary>
/// default .ctor is no cache policy
/// </summary>
public HttpCachePolicyAttribute()
public HttpCacheControlPolicyAttribute()
{

_cacheControl = new CacheControlHeaderValue()
Expand All @@ -31,7 +27,7 @@ public HttpCachePolicyAttribute()
};
}

public HttpCachePolicyAttribute(bool isPrivate, int maxAgeInSeconds) : this()
public HttpCacheControlPolicyAttribute(bool isPrivate, int maxAgeInSeconds) : this()
{
_cacheControl = new CacheControlHeaderValue()
{
Expand Down
2 changes: 1 addition & 1 deletion src/CacheCow.Server/CacheCow.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<Compile Include="CacheRefreshPolicy\HttpCacheRefreshAttribute.cs" />
<Compile Include="CacheRefreshPolicy\ICacheRefreshPolicy.cs" />
<Compile Include="CacheControlPolicy\AttributeBasedCacheControlPolicy.cs" />
<Compile Include="CacheControlPolicy\HttpCachePolicyAttribute.cs" />
<Compile Include="CacheControlPolicy\HttpCacheControlPolicyAttribute.cs" />
<Compile Include="CacheControlPolicy\CacheControlPolicyBase.cs" />
<Compile Include="CacheControlPolicy\ICacheControlPolicy.cs" />
<Compile Include="CachingHandler.cs" />
Expand Down
11 changes: 11 additions & 0 deletions src/CacheCow.Server/CachingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,17 @@ protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage reques
response.Headers.TryAddWithoutValidation(HttpHeaderNames.CacheControl, cacheControlHeaderValue.ToString());
// harmonise Pragma header with cachecontrol header
if (cacheControlHeaderValue.NoCache)
{
response.Headers.TryAddWithoutValidation(HttpHeaderNames.Pragma, "no-cache");
}
else
{
if (response.Headers.Contains(HttpHeaderNames.Pragma))
response.Headers.Remove(HttpHeaderNames.Pragma);
}
}
};
Expand Down
30 changes: 15 additions & 15 deletions src/Common/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System.Reflection;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyCompany("Ali Kheyrollahi")]
[assembly: AssemblyCopyright("Copyright © Ali Kheyrollahi 2012")]

[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyConfiguration("")]

[assembly: AssemblyVersion("0.3.0.0")]
[assembly: AssemblyFileVersion("0.3.0.0")]
[assembly: AssemblyInformationalVersion("0.3.0")]
using System.Reflection;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyCompany("Ali Kheyrollahi")]
[assembly: AssemblyCopyright("Copyright © Ali Kheyrollahi 2012")]

[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyConfiguration("")]

[assembly: AssemblyVersion("0.4.0.0")]
[assembly: AssemblyFileVersion("0.4.0.0")]
[assembly: AssemblyInformationalVersion("0.4.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void TestDefaultControllerOrActionLevelPolicy()

namespace CacheCow.Tests.Server.CachePolicy.Controllers
{
[HttpCachePolicy(false, 110)]
[HttpCacheControlPolicy(false, 110)]
public class CachePolicyController : ApiController
{
public string Get(int id)
Expand All @@ -86,10 +86,10 @@ public string Get(int id)
}
}

[HttpCachePolicy(false, 110)]
[HttpCacheControlPolicy(false, 110)]
public class CachePolicyActionController : ApiController
{
[HttpCachePolicy(false, 120)]
[HttpCacheControlPolicy(false, 120)]
public string Get(int id)
{
return "CacheCow";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public void TestControllerLevelPolicy()
request.Properties.Add(HttpPropertyKeys.HttpRouteDataKey, (object)routeData);
var attributeBasedCachePolicy = new AttributeBasedCacheRefreshPolicy();


// act
var refresh = attributeBasedCachePolicy.DoGetCacheRefreshPolicy(request, configuration);

Expand Down

0 comments on commit 5bcd385

Please sign in to comment.