programming the cache api. namespace microsoft.applicationserver.caching { public sealed class...
Post on 21-Dec-2015
234 views
TRANSCRIPT
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(); }}
<?xml version="1.0"?><configuration><configSections><!-- required to read the <dataCacheClient> element --><section name="dataCacheClient" type="Microsoft.ApplicationServer.Caching.DataCacheClientSection, Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /></configSections><dataCacheClient><hosts><host name="Demo2010a" cachePort="22233" /></hosts></dataCacheClient></configuration>
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);
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
//create DataCacheFactory based on config filevar dcf = new DataCacheFactory();
//get the cache named "TestCache"var cache = dcf.GetCache("TestCache");
//Add an item called "Test" - throws if existscache.Add("Test", new Data {TheData = "Test" });
//Put an item called "Test2" - overwrites if existscache.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);}
<?xml version="1.0"?><configuration><configSections><!-- required to read the <dataCacheClient> element --><section name="dataCacheClient" type="Microsoft.ApplicationServer.Caching.DataCacheClientSection, Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /></configSections><dataCacheClient>
<localCache isEnabled="true"
sync="TimeoutBased" objectCount="100000"
ttlValue="300" /><hosts><host name="Demo2010a" cachePort="22233" /></hosts></dataCacheClient></configuration>