使用 class 属性为 post 锐化方法缓存自定义缓存键

Customizing cache key using class properties for post sharp method caching

我想知道是否可以使用私有字符串标识符和函数输入参数 a 使用 postsharp 来缓存 class ABC 的 TestMethod。

    public Class ABC {

    private string identifier;

    public ABC(string identifier){

       this.identifier = identifier;

    }

    public int TestMethod(int a){
        return 0;
    }
}

是的,这是可能的。缓存键还包括 this 转换为字符串的值。因此,您可以覆盖 ABC class 的 ToString() 方法以包含 identifier。或者您可以为 ABC.

创建自定义格式化程序 class

此外,请参阅以下文档页面以供参考: