The caching of data in BlogEngine.NET becomes a problem when BE.NET is installed in a web farm. When you add, edit or delete a post, that change is occurring on one machine within the farm as well as within the data store (App_Data or DB). But the other servers within the farm are unaware there’s been a change in data. Not until the data loaded in memory on these other servers clears out anywhere from minutes to hours to days later, the old set of data will continue to be shown to visitors hitting one of these other servers.
I created a WebFarm extension which may help some people in this situation. I haven’t worked much with web farms, so I’m not sure how well this extension will work. Any feedback is appreciated. I was able to test this extension on Vista/IIS7 where I had two separate web applications pointing to the same physical BE.NET location on my machine. Even in this situation, creating a new post within one application would normally result in the post NOT showing up in the other application. This new Web Farm extension did solve the caching problem for this scenario. I’m hoping this success will carry over to a Web Farm scenario.
There’s two files in the ZIP file download. WebFarm.cs should go in the App_Code\Extensions folder. The other file, webfarm_data_update_listener.ashx, should go in the root of your blog.
Once those files are in their correct locations, if you go to the Extensions tab in the control panel, you’ll want to click ‘Edit’ for this new WebFarm extension.

I wanted the help box on the right side to include as much information as possible. But as you can see, the Extensions page doesn’t currently handle long description boxes very well :)
The idea behind this extension is that if each server within the farm has a unique internal Ip address, this extension can notify each server that a change in data has occurred. Not knowing a lot about web farms, this is the part I’m unsure is possible. But it does some reasonable each server would have its own unique IP address. If you’re using host headers, this extension may not work for you – unless you have a unique URL to each server within the farm.
The extension currently notifies the servers in the web farm when a new post or page has been created, updated or deleted. Other data such as Settings, Profiles, Categories, Comments, etc. is not handled by this extension. Or at least not in this version.
The webfarm_data_update_listener.ashx file you placed in the root of the blog is the handler that receives notifications when a change in Post or Pages has occurred. The data passed to the handler includes the type of data changed (Post, Page), the type of change (Insert, Update, Deletion) and the ID of the Post or Page that has been inserted/updated/deleted. Rather than the handler re-loading all the Post/Page data, it will insert, update or delete just the one piece of data that changed. This is more efficient than re-loading all the data which could be taxing for those with a lot of blog data.
As described in the help area when adding the server Ip/Urls in the WebFarm extension, make sure the “Shared Key” you enter matches the key in the webfarm_data_update_listener.ashx handler file. The default key in the handler is “blogengine”. For security purposes, you may change the key in the ASHX handler. But be sure the ASHX key matches the key you enter for each Ip/Url.
Also, because of this same data caching issue in web farms, after you enter all the web farm server Ip addresses into the WebFarm extension, you’ll want to re-start BE.NET so the extension data you just entered is detected by all the servers in your farm. Updating the web.config file with any meaningless change will accomplish re-starting the blog application. This is just a one-time requirement so all servers have the list of servers they need to notify when a post or page change has occurred.
I realize this extension has its limitations and isn’t a comprehensive solution to undesired caching in a web farm scenario. But it does handle propagating changes in posts across the servers in the farm – one of the more important areas. This extension is also easy to get started with in contrast to making various changes within BE.NET itself. Again, any feedback on this extension is appreciated.
Download: WebFarmExtension_1.0.zip (3.26 kb)