Refresh Posts - Clear Cache

by Arnold Matusz 12 12 2008

Lately I’ve come across an interesting situation involving BlogEngine.Net. I normally use Windows Live Writer to write my blog posts, and as I really love to post some programming related articles I use Syntax Highlighter. Sadly I don’t have Windows Live Writer set up (with all the plugins) on each workstation I work on, so whenever I need to change something in a post (typos, updates, etc.) and WLW is not at hand I get down and dirty and edit the XML files which the posts are saved in.

I hear you asking: Why you stupid idiot are you doing that when you can edit your posts in a nice WYGIWYS editor? Well, the only reason is that when I post code samples those need to be in pre tags where each and every space i very important. And after I edit/save a post in BE’s (online) the formatting is lost.

So, back to the situation, you download your XML file, edit what you need … and after you upload it back to its place you notice that the post remains the same when viewing it in the browser. This is due to the fact that BlogEngine is heavily caching blog posts for you to have an almost instance response when you access the website. This is an awesome technique which definitely does not need to be changed, but we can find a little workaround so we can clear the cache whenever we want to.

After a short search I came across the Reload() method which many people suggested will solve the issue.

        catch { }

But sadly after further investigation I realized that this only refreshes the list of posts. In fact to solve the issue you only have to use some native ASP.NET code from the HttpRuntime class.

MSDN Source: – HttpRuntime.Close() –> Removes all items from the cache.

I created a page called Reset.aspx in the /Admin/Pages folder which contains a Button and a Label (for displaying a status message – or error message :) ).

        <asp:Button ID="btnReset" runat="server" Text="Reset" OnClick="btnReset_Click"/>
        <asp:Label ID="lblResult" runat="server"></asp:Label>

The corresponding event handler:

    protected void btnReset_Click(object sender, EventArgs e)
            lblResult.Text = "Reload successful!";
            lblResult.Text = "Not successful!";

For this page to be visible in your admin panel’s menu section you need to edit your web.sitemap file located in the root of the BlogEngine instance by adding the following line of markup.

    <siteMapNode url="~/admin/Pages/Reset.aspx"  title="reset" 
description="" roles="administrators"/>

Now, whenever for NO GOOD reason you need to edit your blog post files offline, you can clear the cache at the push of a button.

DZone it Digg it Submit to StumbleUpon Submit to Technorati Submit to Submit to Submit to NewsVine Submit to Furl Submit to BlinkList

Tags: , ,

Programming | C# | ASP.NET


12/12/2008 3:17:47 AM #

Yoann. B


Great tips, thanks

Check out my BlogEngine Blog Posts :

Yoann. B France |

12/12/2008 10:16:14 AM #


Trackback from Web Development Community

Arnold Matusz's Blog | Refresh Posts - Clear Cache

Web Development Community |

12/17/2008 12:32:31 PM #

Michael Silvester

Hi Arnold,

Great blog post mate!

Listen, can I hire you to make some changes
to a project that we have worked on earlier?

Looking forward to hearing from you mate!

Take Care,

Michael Silvester

Michael Silvester Australia |

3/4/2010 4:17:42 AM #


Refresh Posts - Clear Cache

Refresh Posts - Clear Cache

神秘园 |