1

This doesn't give desired results, if I add more records in the database they appear immediately on the RSS feed.

Sorry, just to be entirely clear, I'm expecting:

  • I run the page
  • I see results
  • I add a record in the DB
  • It doesn't appear on the feed as it's loading a cached version
  • It appears later when the cache has expired

At the moment new records appear in the feed immediately.

<%@ WebHandler Language="C#" Class="BlogRSS" %>

using System;
using System.Web;
using System.Web.UI;
using System.Linq;

public class BlogRSS : IHttpHandler {

    public void ProcessRequest (HttpContext context) {

        // Cache this
        OutputCacheParameters CacheSetting = new OutputCacheParameters();
        CacheSetting.Duration = 10;

        // Print out response
        context.Response.ContentType = "text/xml";
        context.Response.Write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        context.Response.Write("<rss xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:atom=\"http://www.w3.org/2005/Atom\" version=\"2.0\">\n\n");

        context.Response.Write("<channel>\n");
        context.Response.Write("\t<title>Scirra Blog</title>\n");   
        context.Response.Write("\t<link>" + Settings.MasterDomainRoot + "/Blog</link>\n");
        context.Response.Write("\t<description>Construct, Scirra and general game industry news - Scirra.com</description>\n");
        context.Response.Write("\t<language>en-us</language>\n\n");

        context.Response.Write("\t<image>\n");
        context.Response.Write("\t\t<title>Scirra Blog</title>\n");         
        context.Response.Write("\t\t<url>" + Settings.MasterDomainRoot + "/Images/blog-icon-small.png</url>\n");    
        context.Response.Write("\t\t<width>100</width>\n"); 
        context.Response.Write("\t\t<height>91</height>\n");        
        context.Response.Write("\t\t<height>91</height>\n");
        context.Response.Write("\t\t<link>" + Settings.MasterDomainRoot + "/Blog</link>\n");            
        context.Response.Write("\t</image>\n\n");

        context.Response.Write("\t<xhtml:meta xmlns:xhtml=\"http://www.w3.org/1999/xhtml\" />\n\n");

        // Get all blog entries
        using (DataClassesDataContext db = new DataClassesDataContext())
        {
            var q = (from Entry in db.tblBlogEntries orderby Entry.date descending select new { Entry.date, Entry.description, Entry.ID, Entry.title });
            foreach (var Rec in q)
            {
                PrintEntryXML(Rec.ID, Rec.title, Rec.description, Rec.date.Value);
            }
        }

        context.Response.Write("</channel>\n");
        context.Response.Write("</rss>\n");

    }

    /// <summary>
    /// Prints out an item
    /// </summary>
    public static void PrintEntryXML(int EntryID, string Title, string Description, DateTime PublishDate)
    {
        HttpContext.Current.Response.Write("\t<item>\n");

        HttpContext.Current.Response.Write("\t\t<title>" + Title + "</title>\n");
        HttpContext.Current.Response.Write("\t\t<link>" + Settings.MasterDomainRoot + "/Blog/" + EntryID + "/" + SEO.FriendlyURL(Title) + "</link>\n");
        HttpContext.Current.Response.Write("\t\t<description>\n");
        HttpContext.Current.Response.Write("\t\t\t" + Description + "\n");
        HttpContext.Current.Response.Write("\t\t</description>\n");
        HttpContext.Current.Response.Write("\t\t<pubDate>" + CommonFunctions.PubDate(PublishDate) + "</pubDate>\n");

        HttpContext.Current.Response.Write("\t</item>\n\n");
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}

I've tried setting it to a big number as well. I'm not modifying source between requests either.

2
  • 2
    You have omitted: 1. The desired results. 2. A question. Commented Apr 13, 2011 at 18:58
  • @Oded I thought I did make it clear but I added in more detail at the beginning anyway Commented Apr 13, 2011 at 19:02

1 Answer 1

2

Are you missing a call to InitOutputCache? I'm not sure how this works in a handler, but I think you would need that if this were a page.

This question may help:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.