惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
Stack Overflow Blog
Stack Overflow Blog
人人都是产品经理
人人都是产品经理
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Vercel News
Vercel News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Y
Y Combinator Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
V
Visual Studio Blog
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
博客园 - 司徒正美
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
L
LangChain Blog

博客园 - yiyanxiyin

一个linq左连接查询速度问题 利用vba实现excel表格连接打印编号(一页两个编号),编号支持前缀 使用反射让linq实现动态查询, 类似拼接sql语句的where 条件 中断工作流并持久化到数据库中【源码】 按模板生成word报表,可扩展,demo可生成多页 固定table的行列 固定table的cell宽度,多余的文字隐藏 - yiyanxiyin - 博客园 wcf中异步与双向通讯的区别 解决msmq私有队列不能持久保存的问题 sqlserver中使用查询分析器的一点小技巧 原创:一个相当有用的宏(for vs.net),该宏能大大的提高开发速度 Response.Redirect()与Server.Transfer()的区别 cellIndex在隐藏td中的问题,bug?(ie6) - yiyanxiyin - 博客园 一个format格式问题 - yiyanxiyin - 博客园 参透js 搞不懂的js 个人作品:全文搜索Access中的数据(附.net源代码) 个人作品:存储过程代码生成器(for MS SQL Server) 原创技术文章:保存帐号信息通用类(使用Session或者Cookie)
在非asp.net程序中使用缓存
yiyanxiyin · 2008-06-26 · via 博客园 - yiyanxiyin

下面是一个控制台的例子,在.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());
            }
        }
    }
}