下面是一个控制台的例子,在.net remoting,wcf等分布式程序的中间层也可以这样使用:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Caching;
using System.Web;

namespace ConsoleApplication1
{

    class CacheExample
    {
        public CacheExample()
        {

        }

        public string GetString()
        {
            Cache cache = HttpRuntime.Cache;
            if (cache["string_key"] == null)
            {
                Console.WriteLine("cache it");

                cache["string_key"] = "23333333333333333";

                return cache["string_key"].ToString();

            }
            else
            {
                Console.WriteLine("from cache");
                return cache["string_key"].ToString();
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 5; i ++)
            {
               Console.WriteLine( new CacheExample().GetString());
            }
        }
    }
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-01
  • 2021-08-13
  • 2021-12-28
  • 2022-12-23
猜你喜欢
  • 2021-09-15
  • 2021-09-02
  • 2021-08-25
  • 2021-08-01
  • 2022-02-03
  • 2021-05-19
  • 2022-01-23
相关资源
相似解决方案