Bul*_*nes 6 c# asp.net caching outputcache
问候!
我创建了一个APSX Web表单,它根据一些提供的参数返回一个远程图像.它可以像这样使用:
<img src="/ImageGetter.aspx?param1=abc¶m2=123" />
Run Code Online (Sandbox Code Playgroud)
ImageGetter.aspx的标记和代码看起来类似于:
<%@ OutputCache Duration="100000" VaryByParam="*" Location="ServerAndClient" %>
<%@ Page Language="C#" AutoEventWireup="false" EnableSessionState="False" CodeBehind="ImageGetter.aspx.cs" Inherits="ACME.Helpers.ImageGetter" %>
Run Code Online (Sandbox Code Playgroud)
此代码在ImageGetter.aspx的Page_Load方法中调用:
byte[] data = null;
Dictionary<string, string> file_locations = GetImageLocations(param1, param2);
try
{
data = new WebClient().DownloadData(file_locations["main"]);
}
catch (WebException wex)
{
try
{
data = new WebClient().DownloadData(file_locations["backup"]);
}
catch (Exception e)
{
throw;
}
}
Response.ContentType = "image/jpeg";
Response.OutputStream.Write(data, 0, data.Length);
Response.End();
Run Code Online (Sandbox Code Playgroud)
从我的测试来看,它似乎不是缓存.这可能与输出缓存有关,还是应该根据查询字符串参数编写自己的缓存来存储字节数组?
Cod*_*ain 10
尝试删除Response.End(),因为这将提前终止线程并阻止输出缓存发生.
请参阅:http://bytes.com/groups/net-asp/323363-cache-varybyparam-doesnt-work
您可能希望考虑使用ASHX处理程序并使用自己的缓存方法.
| 归档时间: |
|
| 查看次数: |
3213 次 |
| 最近记录: |