香港金道贵金属有限公司,东皇薄荷,dark blue vol.1
public static class distributedcacheextensions { public static titem getorcreate<titem>(this idistributedcache cache, string key, func<distributedcacheentryoptions, titem> factory) { titem t = default(titem); byte[] vs = cache.get(key); if (vs == null) { var options = new distributedcacheentryoptions(); t = factory.invoke(options); cache.set(key, messagepack.messagepackserializer.serialize<titem>(t), options); } else { t = messagepack.messagepackserializer.deserialize<titem>(vs); } return t; } public static async task<titem> getorcreateasync<titem>(this idistributedcache cache, string key, func<distributedcacheentryoptions, task<titem>> factory) { titem t = default(titem); byte[] vs = cache.get(key); if (vs == null) { var options = new distributedcacheentryoptions(); t = await factory.invoke(options); await cache.setasync(key, messagepack.messagepackserializer.serialize<titem>(t), options); } else { t = messagepack.messagepackserializer.deserialize<titem>(vs); } return t; } }
user user = _distributedcache.getorcreate("key", (options) => { options.absoluteexpirationrelativetonow = timespan.fromseconds(20); return new user { id = 1, name = "bidianqing" }; });
[datacontract] public class user { [datamember(order =0)] public int id { get; set; } [datamember(order = 1)] public string name { get; set; } }
install-package messagepack
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论