ServiceStack 是一個高性能的 .NET Web 服務框架,簡化了開發 XML、JSON、JSV 和 WCP SOAP Web 服務。它定義了符合 Martin Fowlers 數據傳輸對象模式,這是一個跨平台的 Web 服務框架。
接下來介紹ServiceStack.Caching的使用教程:
1、添加程序包引用

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接口中提供的方法,不一一列舉,見下方貼圖

本人為.net開發程序猿,技術還是很渣,但我相信總有一天自己也能成為大牛!與君共勉!
如有錯誤的地方望廣大博友評論指正。