Presentation is loading. Please wait.

Presentation is loading. Please wait.

Windows Server AppFabric Cache

Similar presentations


Presentation on theme: "Windows Server AppFabric Cache"— Presentation transcript:

1 Windows Server AppFabric Cache
Patterns of use

2 Outline Reference data Activity data Resource data Priming Batching

3 Classify your data When using the cache
Classification can help organize Caches Regions Remember that availability, expiration, and eviction are set on a per cache basis Reference Activity Resource Primary Read Only Read-Write Not shared Read-Write, Shared Catalog Data Shopping Cart Auction Data/Seat Assignment

4 Reference data Data that doesn’t change often (or at all)
List of countries, catalog items, descriptions, images Excellent candidate for caching Since it doesn’t change frequently also a good candidate for using with local cache Think about turning off expiration and eviction

5 Activity Data Typically data relating to one client Important data
Shopping cart Important data Configure high availability (HA) Can also use Session provider from ASP.NET

6 Resource data Data that is contentious Need to use locking
Seating assignment for flights or concerts Need to use locking Optimistic Pessimistic

7 Using Optimistic concurrency
Clients must retrieve DataCacheItemVersion Pass to overload of DataCache.Put If newer version is already in the cache Put throws an exception Use DataCache.GetCacheItem to retreive the DataCacheItemVersion DataCache.Get does have overload with an out param DataCache.GetIfNewer to avoid full round trip

8 Concurrency APIs public DataCacheItemVersion Put(string key, object value, DataCacheItemVersion oldVersion); public DataCacheItemVersion Put(string key, object value, DataCacheItemVersion oldVersion, string region); public DataCacheItemVersion Put(string key, object value, DataCacheItemVersion oldVersion, TimeSpan timeout); public DataCacheItemVersion Put(string key, object value, DataCacheItemVersion oldVersion, TimeSpan timeout, string region); Parameter description key Key of item in the distributed cache value Value of object stored in the cache (serialized) timeout How long before the item should expire oldVersion DataCacheItemVersion held by client region Region to place item

9 Using optimistic concurrency
var version = cache.Add("NewKey", "NewValue"); try { cache.Put("NewKey", "OtherValue", version); } catch (DataCacheException ex) Console.WriteLine(ex.ToString()); //some other process or thread cache.Put("NewKey", "ChangedValue");

10 On demand This is the most typical pattern of cache usage
Application looks for cached data If not found pulls from real data source Puts the data in the cache AKA Cache-aside pattern

11 On demand object data = null; var key = "DataKey";
data = cache.Get(key); if (data == null) { data = GetData(); cache.Add(key, data); }

12 Priming Priming is a pattern where you pull data into the cache before the first request for it Typically done on application start Priming is especially useful with Reference data

13 Batching Batching in general is always more effective
Best used with reference data Used with Tags or Regions in AppFabric Cache DataCache.BulkGet List<string> keys = GetKeys(); var batchItems = cache.BulkGet(keys, "BulkRegion");

14 Summary You need to classify the data you are storing in the cache to be able to choose the correct features DataCacheVersion enables optimistic concurrency pattern (resource data)

15 Questions?


Download ppt "Windows Server AppFabric Cache"

Similar presentations


Ads by Google