任何人都可以提供一个如何与温莎城堡缓存工作的例子。与温莎城堡AOP缓存
我相信作为一个起点,我定义我CacheAspect
从IInterceptor继承如下:
public class CacheAspect : IInterceptor
{
public void Intercept(IInvocation invocation)
{
// Code here to check if data is in cache and if so
// put that into invocation.ReturnValue... job done!
// If not then invoke the method
invocation.Proceed();
// Now cache the result of the invocation
}
}
然后我就可以装点的任何方法与我CacheAspect
...
[Interceptor(typeof(CacheAspect))]
public List<string> GetStaticData()
{
}
..和当然在Windsor容器中注册整个东西。
但是......
我如何可以改变的时间我想在每个方法调用我的缓存东西的多少?在这个例子中,我可能希望它被缓存60分钟。对于其他例子一天等等等。我必须为每个缓存持续时间创建
CacheAspect
吗?从每种方法中识别每个缓存值的最佳方法是什么?例如,使用
invocation.TargetType.Name
和invocation.Method.Name
的组合?在问题2上展开 - 如果传入了参数会怎么样?然后,我需要确定是否已缓存匹配特定参数集的数据。
谢谢。