filipw / Strathweb.CacheOutput

ASP.NET Web API CacheOutput - library to allow you to cache the output of ApiControllers
Other
882 stars 253 forks source link

InvalidateCacheOutput the get function of another controller #153

Closed josunedesosa closed 8 years ago

josunedesosa commented 9 years ago

I have a problem with "InvalidateCacheOutput" header. I have two controllers: TipoDatosController y ValorDatosController.

1) TipoDatosController: I have this method:

[VersionedRoute("TipoDatos/{id}/ValorDatos", 1)]
    [CacheOutput(ClientTimeSpan = 86400, ServerTimeSpan =86400)]
    [HttpGet]
    public async Task<IHttpActionResult> GetValorDatos([FromUri] int id)
{

}

2) ValorDatosController: when I post a new valor with next method, I want to invalidate the cache of "GetValorDatos" in "TipoDatosController"

[InvalidateCacheOutput("GetValorDatos", typeof(TipoDatosController))]        
    public async Task<IHttpActionResult> Post(ValorDato valor)
{
}

I put the following notation but does not work: [InvalidateCacheOutput("GetValorDatos", typeof(TipoDatosController))]

How can do this with InvalidateCacheOutput header??

If I use a manual invalidation, it works.:

var cache = Configuration.CacheOutputConfiguration().GetCacheOutputProvider(Request); cache.RemoveStartsWith(Configuration.CacheOutputConfiguration().MakeBaseCachekey((TipoDatosController t) => t.GetValorDatos(valor.Id)));

Thanks a lot,

Josune

Iamcerba commented 9 years ago

I believe that the problem is within constructor of InvalidateCacheOutputAttribute:

public InvalidateCacheOutputAttribute(string methodName, Type type = null)
{
   this._controller = type != (Type) null ? type.Name.Replace("Controller", string.Empty) : (string) null;
   this._methodName = methodName;
}

Should be:

public InvalidateCacheOutputAttribute(string methodName, Type type = null)
{
   this.controller = type != (Type)null ? type.FullName : (string)null;
   this.methodName = methodName;
}
alexwiese commented 8 years ago

Fixed in #162

filipw commented 8 years ago

this is now on nuget https://www.nuget.org/packages/Strathweb.CacheOutput.WebApi2/0.10.0