220 likes | 354 Views
MID302. AppFabric Caching: How It Works and When You Should Use It . Jon Flanders Senior Consultant MCW Technologies. Agenda. Why Caching? What is AppFabric Cache? On-Premise and in Azure Demo, demo, demo. Typical Web Architecture. Problems with typical architecture.
E N D
MID302 AppFabric Caching: How It Works and When You Should Use It Jon Flanders Senior Consultant MCW Technologies
Agenda • Why Caching? • What is AppFabric Cache? • On-Premise and in Azure • Demo, demo, demo
Problems with typical architecture • Storing session in memory leads to scalability problems • Sticky sessions solve this • Most cloud providers don’t enable • Data tier is difficult to scale out • Portioning is one way • No product gives you this automatically
How do you scale this architecture? • Caching data from the data tier has been one typical pattern • Reduces load on database • Reduces network round-trips • Caching in memory of web tier can lead to cache coherency problems • CEO gets one good financial report from Web Node 1 – refreshes and gets bad financial report from Web Node 2 • One of these is stale
Definitions • Caching • Storing a copy of data closer to application logic, away from its source • Distributed Caching • A set of nodes in a farm that coordinate to create a unified view of a cache to a caching client • Expiration • When an object is removed from the cache because of staleness • Eviction • When an object is removed from the cache due to low memory conditions
What is AppFabric Cache? • A distributed cache for “data” • An in-memory cache (no paging to disk or persistence layer) • The “Data” can be • Any (serializable) CLR Object • XML • Binary data • Optimized for the cache-aside pattern (in this version) • Programming against the cache uses explicit API • Changing the cache doesn’t update the original data store
Windows *Server* AppFabric Cache • Cache runs on N nodes • Nodes that share configuration are part of a single Cache Cluster • Runs as a Windows Service (one service per server node) • Typically not the same servers as the client (web) tier • More memory is better • In-memory copy cache is optional setting (“Local Cache”) • All the cache nodes in a cluster are part of a fabric • Share configuration • Communicate • Cooperate
Windows *Azure* AppFabric Cache • Essential if you are building Azure Web or Worker roles • APIs are identical • You don’t have to manage cache cluster • Can increase and decrease capacity using configuration rather than physical hosts • 128MB to 4GB per named cache – you don’t lose data when you increase cache size • Normal eviction policies apply if you decrease cache size
AppFabric Cache advantages • Native .NET API • Scalability • Performance • Typically linear as more nodes are added • LocalCache increases raw performance • High Availability • Distributed nature safeguards against cache client and server failures
Current deltas between server and Azure • Some server features not available ATM • No Notifications, HA, Tags/Regions • Expiration • No way to change expiration on a cache –but can be changed on a per-object basis • Eviction • No way to change eviction settings • Connections • Server: one connection ==multiple named caches • Azure: one connection == named default cache • Azure – create multiple namespace reservations
When to use it: • Reference data • Activity data • Resource data
ASP.NET Session State Provider • Included OOB with the Cache • Simple configuration change • Enables session state to be cached across a cluster
Session state provider • <sessionStatemode="Custom"customProvider="SessionStoreProvider"> • <providers> • <addname="SessionStoreProvider"type="Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider, Microsoft.ApplicationServer.Caching.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"cacheName="BlueYonderSession"/> • </providers> • </sessionState>
Summary • Windows Server AppFabric Cache is a distributed application cache • Caching is important to application scalability • Explicit caching API available to .NET 3.5 SP1 and .NET 4.0 • ASP.NET Session provider an implicit way to take advantage of the Cache’s capabilities
Required Slide Track PMs will supply the content for this slide, which will be inserted during the final scrub. Track Resources • Windows Azure Platform Training Kit • Windows Server AppFabric Training Kit • BizTalk 2010 Developer Training Kit • AppFabric Team Blog • Windows Azure AppFabric on MSDN • Windows Server AppFabric on MSDN
Resources • Connect. Share. Discuss. http://northamerica.msteched.com Learning • Sessions On-Demand & Community • Microsoft Certification & Training Resources www.microsoft.com/teched www.microsoft.com/learning • Resources for IT Professionals • Resources for Developers http://microsoft.com/technet http://microsoft.com/msdn