I am trying to cache the pdf output of my DuoDimension plugin. When I try the following, it never seems to find the cache record. Any ideas for this?
Code:
public partial class printproject : SkinBase
{
protected void Page_Load(object sender, System.EventArgs e)
{
int productid = CommonLogic.QueryStringUSInt("productid");
int projectid = CommonLogic.QueryStringUSInt("projectid");
try
{
String CacheName = "ProjectPDF_" + projectid;
Response.CacheControl = "private";
Response.Expires = 0;
Response.AddHeader("pragma", "no-cache");
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "inline; filename=" + projectid + ".pdf");
string XmlPackageName = "printprojects.xml.config";
string cached = string.Empty;
SectionTitle = "Project " + projectid + " Download";
Customer ThisCustomer = ((AspDotNetStorefrontPrincipal)Context.User).ThisCustomer;
// Check if PDF is cached
if (AppLogic.CachingOn)
{
DuoDimension.HtmlToPdf cacheconv = (DuoDimension.HtmlToPdf)HttpContext.Current.Cache.Get(CacheName);
if (cacheconv != null)
{
if (CommonLogic.ApplicationBool("DumpSQL"))
{
HttpContext.Current.Response.Write("Cache Hit Found!<br />\n");
}
cacheconv.ShowPDF(cacheconv.SavePDF(), Response);
}
}
DuoDimension.HtmlToPdf conv = new DuoDimension.HtmlToPdf();
StringBuilder html_st = new StringBuilder(AppLogic.RunXmlPackage(XmlPackageName, null, ThisCustomer, 1, String.Empty, String.Empty, true, true));
// PdfDocumentInfo
conv.PdfDocumentInfo.Title = "Project " + projectid;
conv.PdfDocumentInfo.Author = "Me";
conv.PdfDocumentInfo.Creator = "Me";
conv.PdfDocumentInfo.Producer = "© 2001-" + DateTime.Now.Year.ToString() + " Me";
// Document Font Info
conv.PdfTextInfo.FontName = "Arial";
conv.PdfTextInfo.FontSize = 11;
// PageInfo Settings
conv.PageInfo.PageFormat = DuoDimension.ePageFormat.Letter;
conv.PageInfo.PageTopMargin = 70;
conv.PageInfo.PageBottomMargin = 74;
conv.Header = "<br /><img src=http://development/adns/images/projects/pdf_files/top_logo.jpg />";
conv.Footer = "<br /><img src=http://development/adns/images/projects/pdf_files/bottom_info.jpg />";
conv.OpenHTML(html_st);
conv.ShowPDF(conv.SavePDF(), Response);
if (AppLogic.CachingOn)
{
HttpContext.Current.Cache.Insert(CacheName, conv.ToString(), null, System.DateTime.Now.AddMinutes(14400), TimeSpan.Zero);
}
}
catch
{
Response.ContentType = "text/html";
ErrorMsgLabel.Text = "An error has occured. Project #" + projectid + " is currently unavailable. Please try back later.<br />";
}
}
}