日期:2014-05-16  浏览次数:20378 次

ASP.NET 缓存问题
有没有大侠可以提供一些关于ASP.NET  缓存技术的东西?
开发完网站后,数据请求太频繁,服务器很压力很大!!在网上找资料都说可以利用缓存,可就是不知道从何下手~~
请帮忙给些指导~~~

------解决方案--------------------
服务器压力大是好事,不过你的程序得改改了,增加性能,我说几点

第一,静态页面的实现,<%@ OutputCache Duration ="20" VaryByParam="none"  %>是指使用了页面缓存,类似于静态页。

第二,读得多的数据放于APPLICATION或cache中,这样可以重复使用,极大提高效率。像我开发时,有时候都把几十万的数据放入CACHE中,以供统计等功能频繁使用,当然,对服务器的内存要求高,这块是大头。

第三,多用存储过程,这点应该没有什么好说的了吧
------解决方案--------------------
缓存的本质是用空间换取时间。
有两个,
一个是用.NET本身的缓存,有很多种,可以用system.web.caching 里的cache;
还有一个是用分布式缓存,这个也很简单。
网上搜索一下用法吧,都是要写代码,分布式缓存还要配置安装在服务器上。
------解决方案--------------------
引用:
请问一下,我直接在页面头部加下面这一句
<%@ OutputCache Duration ="20" VaryByParam="none"  %>
为什么客户端打开的一直是缓存的页面呢?
我是这样测试的:

A.aspx页面 title=“title1”  ,然后加上<%@ OutputCache Duration ="20" VaryByParam="none"  %>这一句,然后我开始访问这个页面:title=“title1”

然后我马上修改:把A.aspx页面 title=“title2”  
一段时间(20秒)后我访问A.aspx,为什么还是title=“title1”?  

请问这样的测试思路有问题吗?如果没问题,为什么结果没变?


给你写一个测试。

假设所谓的Title来自于后台程序
public static class BLL
{
    public static string Title
    {
        get
        {
            return string.Format("{0}分产生的页面", DateTime.Now.Minute);
        }
    }
}


然后再这个页面中在Title中使用它
<%@ Page Language="C#" EnableSessionState="False" %>

<!DOCTYPE html>
<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        this.DataBind();
    }
</script>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title><%= BLL.Title %></title>
</head>
<body>
    <asp:Label ID="Label1" runat="server" Text="<%# DateTime.Now %>"></asp:Label>
</body>
</html>

这里,当你刷新页面,会看到页面中的时钟每一次都在变化,并且页面Title也正确地反映了BLL类中Title属性的值。

现在,假设我们设置1小时的页面缓存,
<%@ Page Language="C#" EnableSessionState="False" %>
<%@ OutputCache Duration="3600" VaryByParam="none" %>

<!DOCTYPE html>
<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        this.DataBind();
    }
</script>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 &nb