Caching postsharp-基于参数值的缓存

Caching postsharp-基于参数值的缓存,caching,postsharp,Caching,Postsharp,我正在使用postsharp缓存,并创建了一个示例函数来缓存结果——但我只想基于参数值进行缓存 例如,我的函数如下所示 [Cache(SlidingExpiration = OneHour, IgnoreThisParameter = true )] public IEnumerable<String> Get(int dateId) { // code processing } [缓存(滑动过期时间=1小时,忽略此参数=true)] 公共IEnumerable Get(int

我正在使用postsharp缓存,并创建了一个示例函数来缓存结果——但我只想基于参数值进行缓存

例如,我的函数如下所示

[Cache(SlidingExpiration = OneHour, IgnoreThisParameter = true )]
public IEnumerable<String> Get(int dateId)
{
  // code processing
}
[缓存(滑动过期时间=1小时,忽略此参数=true)]
公共IEnumerable Get(int-dateId)
{
//代码处理
}
我希望在dateid=T-1(昨天)时缓存此函数的输出,而不是在dateid不是T时缓存

但在[Cache]属性修饰后,所有内容都会被缓存。基本上,我只想缓存T-1数据,而不想缓存任何其他日期的数据

使用此模式是为了使用自定义方法使缓存无效,但我看不到任何基于选择性参数值的缓存选项


有人能对此做出回应吗?

目前这是不可能的。此时,您需要将方法分为三种方法,并具有:

public IEnumerable<string> Get(int dateId)
{
  if (dateId == CurrentDate - 1)
    GetCached(dateId);
  else
    GetCore(dateId);
}

[Cache(SlidingExpiration = OneHour, IgnoreThisParameter = true )]
private IEnumerable<string> GetCached(int dateId)
{
  return GetCore(dateId);
}

private IEnumerable<string> GetCore(int dateId)
{
  // ...
}
public IEnumerable Get(int-dateId)
{
如果(dateId==CurrentDate-1)
GetCached(dateId);
其他的
GetCore(dateId);
}
[缓存(滑动过期=一小时,忽略此参数=真)]
私有IEnumerable GetCached(int-dateId)
{
返回GetCore(dateId);
}
私有IEnumerable GetCore(int-dateId)
{
// ...
}

这已在待办事项列表中,但目前还没有计划发布任何版本。

目前这是不可能的。此时,您需要将方法分为三种方法,并具有:

public IEnumerable<string> Get(int dateId)
{
  if (dateId == CurrentDate - 1)
    GetCached(dateId);
  else
    GetCore(dateId);
}

[Cache(SlidingExpiration = OneHour, IgnoreThisParameter = true )]
private IEnumerable<string> GetCached(int dateId)
{
  return GetCore(dateId);
}

private IEnumerable<string> GetCore(int dateId)
{
  // ...
}
public IEnumerable Get(int-dateId)
{
如果(dateId==CurrentDate-1)
GetCached(dateId);
其他的
GetCore(dateId);
}
[缓存(滑动过期=一小时,忽略此参数=真)]
私有IEnumerable GetCached(int-dateId)
{
返回GetCore(dateId);
}
私有IEnumerable GetCore(int dateId)
{
// ...
}
这已经在待办事项列表中,但目前还没有计划发布