星空网 > 软件开发 > ASP.net

使用ServiceStack缓存技术

ServiceStack 是一个高性能的 .NET Web 服务框架,简化了开发

接下来介绍ServiceStack.Caching的使用教程:

1、添加程序包引用

使用ServiceStack缓存技术

 

2、新建一个CacheManager类,贴入以下代码

using System;using System.Collections.Generic;using System.Linq;using System.Web;using ServiceStack.Caching;namespace AIP.Web.Utils{  /// <summary>  /// 单例模式 参考:http://csharpindepth.com/Articles/General/Singleton.aspx  /// </summary>  public sealed class CacheManager  {    private static readonly Lazy<CacheManager> lazy = new Lazy<CacheManager>(() => new CacheManager());    public static CacheManager Instance    {      get { return lazy.Value; }    }    public ICacheClient CacheClient { get; set; }    private CacheManager()    {      CacheClient = new MemoryCacheClient();    }  }}

3、Caching存储是以键值对的方式,并提供过期时间设置

(1)、添加一个缓存数据

Utils.CacheManager.Instance.CacheClient.Add(key, value);

(2)、添加一个缓存数据并设置过期时间

Utils.CacheManager.Instance.CacheClient.Set(key, value,Time);

(3)、获取缓存中的所有Key

Utils.CacheManager.Instance.CacheClient.GetAllKeys();

(4)、获取指定Key的缓存数据的值

Utils.CacheManager.Instance.CacheClient.Get<string>(key);

(5)、清除指定Key的缓存数据

Utils.CacheManager.Instance.CacheClient.Remove(key);

...

4、ICacheClient接口中提供的方法,不一一列举,见下方贴图

使用ServiceStack缓存技术

 

本人为.net开发程序猿,技术还是很渣,但我相信总有一天自己也能成为大牛!与君共勉!

如有错误的地方望广大博友评论指正。

 




原标题:使用ServiceStack缓存技术

关键词:缓存

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

打击刷单新手段:亚马逊降权大杀器出动!:https://www.ikjzd.com/articles/149836
快速的ODI境外投资备案找哪家:https://www.ikjzd.com/articles/149838
快速的odi企业境外投资备案哪家好呢?:https://www.ikjzd.com/articles/149839
国际e邮宝要涨价了,中美卖家日子都不好过了!:https://www.ikjzd.com/articles/14984
快速的ODI企业境外投资备案选哪家:https://www.ikjzd.com/articles/149840
快速的企业境外投资备案哪家强:https://www.ikjzd.com/articles/149841
日本jct如何注册流程详解:https://www.kjdsnews.com/a/1842253.html
日本jct如何注册流程详解:https://www.xlkjsw.com/news/93307.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流