使用ServiceStack缓存技术

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开发程序猿,技术还是很渣,但我相信总有一天自己也能成为大牛!与君共勉!

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

 

转载于:https://www.cnblogs.com/heresion/p/20161109_ServiceStackCaching.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值