方法 GetIfNewer
获取如果更新(字符串,参考 CacheItemVersion)
仅当缓存中存在较新版本的对象时,才从缓存中获取对象。
声明
T GetIfNewer<T>(string key, ref CacheItemVersion version)
参数
Type | 名称 | 课程描述 |
---|---|---|
系统字符串 | 键 | 用于引用所需对象的唯一键。 |
缓存项版本 | 版本 | 通过引用传递的指定对象的版本。 |
退货政策
Type | 课程描述 |
---|---|
T | 如果缓存中存在较新的对象,则返回该对象。 否则,返回 null。 |
类型参数
名称 | 课程描述 |
---|---|
T | 指定从缓存中获取的值的类型。 |
国际私人包机价格项目范例
以下示例演示如何从缓存中获取更新版本的项目(如果存在)。
ICache cache = CacheManager.GetCache("demoCache");
Product product = new Product();
product.Id = 1;
product.Name = "Chai";
string key = "Product0";
CacheItemVersion version = cache.Add(key, product);
Product product = cache.GetIfNewer<Product>(key, ref version);