Azure AppFabric Cache HowTo

by Rok Bermež 2. May 2011 19:24
Well since we now have Azure AppFabric Cache available, let’s get a head start on how to use it in your Cloud ASP.NET (MVC) application. First, you need to have AppFabric 1.0 April Refresh SDK installed on your machine so grab it at here. Next, go to Windows Azure Management portal. Log in, go to AppFabric/Cache and create new service namespace: wait for the service to be activated. Then click 'View Client Configuration Button' you will get a nice pre prepared configuration settings (with all those pesky security information included) for your app: now we have all the pieces of the puzzle ready, all we have to do is to add references to caching dlls (located at C:\Program Files\Windows Azure AppFabric SDK\V1.0\Assemblies\NET4.0\Cache) to our application and change web.config with the settings given by previous step. You would always need to put cache section in <configSections> node: <section name="dataCacheClients" type="Microsoft.ApplicationServer.Caching.DataCacheClientsSection, Microsoft.ApplicationServer.Caching.Core" allowLocation="true" allowDefinition="Everywhere"/> and configure your Cache EndPoints: <dataCacheClients> <dataCacheClient name="default"> <hosts> <host name="ntkonferenca.cache.windows.net" cachePort="22233" /> </hosts> <securityProperties mode="Message"> <messageSecurity authorizationInfo="1AmN0tT371NgUtH@T"> </messageSecurity> </securityProperties> </dataCacheClient> <dataCacheClient name="SslEndpoint"> <hosts> <host name="ntkonferenca.cache.windows.net" cachePort="22243" /> </hosts> <securityProperties mode="Message" sslEnabled="true"> <messageSecurity authorizationInfo="1AmN0tT371NgUtH@T"> </messageSecurity> </securityProperties> </dataCacheClient> </dataCacheClients> If your application uses Session State and you want it to use Azure AppFabric Cache (which you do) you change your <sessionState> node to: <sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider"> <providers> <add name="AppFabricCacheSessionStoreProvider" type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache" cacheName="default" useBlobMode="true" dataCacheClientName="default" /> </providers> </sessionState> and the same for OutputCache by changing <caching> note: <caching> <outputCacheSettings enableFragmentCache="true" defaultProvider="DistributedCache"> <outputCacheProfiles> <add name="default" duration="43000" /> <add name="DistributedCache" type="Microsoft.Web.DistributedCache.DistributedCacheOutputCacheProvider, Microsoft.Web.DistributedCache" cacheName="default" dataCacheClientName="default" /> </outputCacheProfiles> </outputCacheSettings> </caching> That’s it, nothing needs to be changed in your code, your app is configured and ready to be published to the cloud. AppFabric Cache is not a free service even if you won’t be charged anything for its use prior to August 1, 2011. After that the prices are: 128 MB cache for $45.00/month 256 MB cache for $55.00/month 512 MB cache for $75.00/month 1 GB cache for $110.00/month 2 GB cache for $180.00/month 4 GB cache for $325.00/month In my next post, Ill tackle with using AppFabric Cache without using prepared providers by simple GET and PUT statements (lets get rid of HttpRuntime.Cache as well).  

Tags:

.Net | c# | Azure

Windows Azure AppFabric Caching Service Released

by Rok Bermež 30. April 2011 10:52
Finally the Azure thingy I’ve been waiting for the most. From the official source: Today we are excited to announce that the Caching service has been released as a production service.   The Caching service is a distributed, in-memory, application cache service that accelerates the performance of Windows Azure and SQL Azure applications by allowing you to keep data in-memory and saving you the need to retrieve that data from storage or database. We provide 6 different cache size options for you to choose from, varying from 128MB to 4GB.  In order for customers to be able to start using the service and evaluate your needs we are running a promotion period in which we will not be charging for the service for billing periods prior to August 1, 2011. To learn more about the Caching service please use the following resources: ·        Windows Azure AppFabric Caching availability announced!! blog post, including more information on pricing. ·        Video: Introduction to the Windows Azure AppFabric Cache ·        Video: Windows Azure AppFabric Caching – How to Set-up and Deploy a Simple Cache ·        Windows Azure AppFabric FAQ on MSDN ·        MSDN Documentation The service is already available in our production environment at: http://appfabric.azure.com. For questions on the Caching service please visit the Windows Azure Storage Forum. Customers can take advantage of our free trial offer to get started with the Caching service and Windows Azure AppFabric. Just click on the image below and get started today!  

Tags:

.Net | Azure

Windows Azure Cache Dependency

by Rok Bermež 10. April 2011 23:07
We are supposed to get Windows AppFabric Cache real soon, but till than form time to time we need to synchronize content cached inside our Web roles. SqlDependency is one way, but it cannot solve all problems (especialy those that are not based on SQL data). So to help with the matter I wrote AzureStorageCacheDependency that uses Azure storage to know when data is outdated and cache shloul be cleared. If anyone is in need of something similar, here it goes: public class AzureStorageCacheDependency : System.Web.Caching.CacheDependency { private System.Threading.Timer _timer; private int _poolTime; private CloudBlob _blob; private string _key; public AzureStorageCacheDependency(string connectionString, string conteinerAddress, string blobAddress, int poolTime = 5000) { _poolTime = poolTime; using (AzureContext azureContext = new AzureContext(true)) { var storageAccount = CloudStorageAccount.Parse(connectionString); CloudBlobClient blobStorage = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobStorage.GetContainerReference(conteinerAddress.ToLower()); container.CreateIfNotExist(); _blob = container.GetBlockBlobReference(blobAddress.ToLower()); if (!Exists(_blob)) { Reset(); } else { _key = _blob.DownloadText(); } } _timer = new Timer(new System.Threading.TimerCallback(CheckDependencyCallback), this, 0, _poolTime); } public void Reset() { _key = Guid.NewGuid().ToString(); _blob.UploadText(_key); } private void CheckDependencyCallback(object sender) { if (!Exists(_blob) || _key != _blob.DownloadText()) { NotifyDependencyChanged(this, EventArgs.Empty); _timer.Dispose(); } } public static bool Exists(CloudBlob blob) { try { blob.FetchAttributes(); return true; } catch (StorageClientException e) { if (e.ErrorCode == StorageErrorCode.ResourceNotFound) { return false; } else { throw; } } } } public class AzureContext : IDisposable { HttpContext _oldHttpContext; bool _restoreOldHttpContext = false; public AzureContext(bool forceSettingContextToNull = false) { if (forceSettingContextToNull) { _oldHttpContext = HttpContext.Current; HttpContext.Current = null; _restoreOldHttpContext = true; } else { try { HttpResponse response = HttpContext.Current.Response; } catch (HttpException) { _oldHttpContext = HttpContext.Current; HttpContext.Current = null; _restoreOldHttpContext = true; } } } public void Dispose(bool disposing) { if (disposing) { if (_restoreOldHttpContext) { HttpContext.Current = _oldHttpContext; } } } public void Dispose() { Dispose(true); } ~AzureContext() { Dispose(false); } }

Tags:

.Net | c# | ASP.NET | Azure | Web

ASP.NET MVC 3 AJAX REDIRECT RESULT

by Rok Bermež 5. April 2011 14:31
From time to time, we need to selectively redirect the browser to another location as a result of an AJAX action. Just returning RedirectResult won’t do the trick (even if we are used to similar functionality in ASP.NET AJAX in combination with WebForms ). Here is a very simple RedirectResult thet will be appropriate in those scenarios: public class AjaxRedirectResult : RedirectResult { public AjaxRedirectResult(string url): base(url){} public override void ExecuteResult(ControllerContext context) { if (context.RequestContext.HttpContext.Request.IsAjaxRequest()) { JavaScriptResult result = new JavaScriptResult() { Script = String.Format("window.location='{0}';", UrlHelper.GenerateContentUrl(Url, context.HttpContext)) }; result.ExecuteResult(context); } else base.ExecuteResult(context); } }

Tags:

.Net | c# | ASP.NET | mvc | Web

Windows Azure Platform SDK 1.4 Released

by Rok Bermež 11. March 2011 09:14
SDK 1.4 is available and it  fixes several significant bugs including the nasty RDP bug and adds capabilities like multiple administrator support from the enhanced Windows Azure Connect portal. Bug Fixes: Resolved an issue that caused full IIS fail when the web.config file was set to read-only. Resolved an issue that caused full IIS packages to double in size when packaged. Resolved an issue that caused a full IIS web role to recycle when the diagnostics store was full. Resolved an IIS log file permission Issue which caused diagnostics to be unable to transfer IIS logs to Windows Azure storage. Resolved an issue preventing csupload to run on x86 platforms. User errors in the web.config are now more easily diagnosable. Enhancements to improve the stability and robustness of Remote Desktop to Windows Azure Roles. New Features Windows Azure Connect: Multiple administrator support on the Admin UI. An updated Client UI with improved status notifications and diagnostic capabilities. The ability to install the Windows Azure Connect client on non-English versions of Windows. Windows Azure CDN: Windows Azure CDN for Hosted Services: Developers can now use the Windows Azure Web and VM roles as"origin" for objects to be delivered at scale via the Windows Azure CDN. Static content in a website can be automatically edge-cached at locations through out the United States, Europe, Asia, Australia and South America to provide maximum bandwidth and lower latency delivery of website content to users. Serve secure content from the Windows Azure CDN: A new checkbox option in the Windows Azure management portal enables delivery of secure content via HTTPS through any existing Windows Azure CDN account. You may download the new Windows Azure 1.4 SDK here.

Tags:

.Net | Azure

Calendar

<<  October 2018  >>
MonTueWedThuFriSatSun
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Page List

Month List