神秘园 CaBeta.com

奋勇向前,与君共勉

Refresh BlogEngine.net Posts - Clear Cache

from:Arnold Matusz's Blog
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.

try
{
    BlogEngine.Core.Post.Reload();
}
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 :) ).

The corresponding event handler:

protected void btnReset_Click(object sender, EventArgs e)
{
    try
    {
        BlogEngine.Core.Post.Reload();
        //HttpRuntime.Close();
        lblResult.Text = "Reload successful!";
    }
    catch
    {
        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.


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.

Comments

6/3/2010 4:27:15 AM #

เล่นเกมส์ฟรี

I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people.

เล่นเกมส์ฟรี United States

6/6/2010 3:31:03 AM #

pingback

Pingback from halqa.com

Excelentes artículos «  Marketing Online

halqa.com

6/10/2010 11:01:39 AM #

dior outle

I am quite agreen with the write's says about the experiencial knowledge of better living.For home improvement I have glance those sits.I found they benifit for life. I want to buy something to home use. www.mnticsogs.com  Hope you give me a good views

dior outle People's Republic of China

6/11/2010 4:23:44 PM #

air traveling

this is my first visit here, I'm coming from search engine. Would you share your experience using BlogEngine platform?

air traveling United States

8/30/2010 11:57:47 AM #

pay day fast cash loans

This really is a aw some post, i'm happy I recently found. I have been trying to find guest writers for my blog so if you ever decide that's something you are interested in please feel free to contact me. I will be back to look at out more of your articles later!.....

pay day fast cash loans United States

Add comment


(Will show your Gravatar icon)

  Country flag

看不清?点击图片看看
biuquote
微笑得意调皮害羞酷大笑惊讶发呆喜欢可怜尴尬闭嘴噘嘴皱眉伤心抓狂呕吐坏笑漫骂发怒
Loading



我现在的位置 I'm here

RecentComments

Comment RSS
Powered by BlogYi.NET ver:1.9.0.0, original powered by BlogEngine.NET页面加载用时 171.6044 毫秒