Download presentation
Presentation is loading. Please wait.
1
Programming the Cache API
5
namespace Microsoft.ApplicationServer.Caching { public sealed class DataCacheFactory : IDisposable { public DataCacheFactory(); public DataCacheFactory( DataCacheFactoryConfiguration configuration); public void Dispose(); public DataCache GetCache( string cacheName); public DataCache GetDefaultCache(); }
6
DataCacheFactoryConfiguration
7
element --> <section name="dataCacheClient" type="Microsoft.ApplicationServer.Caching.DataCacheClientSection, Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
9
public DataCacheItemVersion Add(string key, object value); public DataCacheItemVersion Add(string key, object value, TimeSpan timeout); public DataCacheItemVersion Put(string key, object value); public DataCacheItemVersion Put(string key, object value, TimeSpan timeout); Parameterdescription keyKey of item in the distributed cache valueValue of object stored in the cache (serialized) timeoutHow long before the item should expire
11
//create DataCacheFactory based on config file var dcf = new DataCacheFactory(); //get the cache named "TestCache" var cache = dcf.GetCache("TestCache"); //Add an item called "Test" - throws if exists cache.Add("Test", new Data {TheData = "Test" }); //Put an item called "Test2" - overwrites if exists cache.Put("Test2", new Data { TheData = "Test2" }); //Get "Test3" - add if not in cache (cache-aside) var test3 = cache.Get("Test3") as Data; if (test3 == null) { test3 = new Data {TheData = "Test3" }; cache.Add("Test3", test3); }
17
element --> <section name="dataCacheClient" type="Microsoft.ApplicationServer.Caching.DataCacheClientSection, Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> <localCache isEnabled="true" sync="TimeoutBased" objectCount="100000" ttlValue="300" />
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.