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

推荐订阅源

V
Visual Studio Blog
Stack Overflow Blog
Stack Overflow Blog
G
Google Developers Blog
Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
L
LangChain Blog
T
The Blog of Author Tim Ferriss
J
Java Code Geeks
Y
Y Combinator Blog
月光博客
月光博客
雷峰网
雷峰网
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
F
Fortinet All Blogs
A
About on SuperTechFans
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
小众软件
小众软件
H
Help Net Security
Last Week in AI
Last Week in AI
B
Blog RSS Feed
宝玉的分享
宝玉的分享
N
Netflix TechBlog - Medium
博客园 - 叶小钗
The GitHub Blog
The GitHub 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());
            }
        }
    }
}