1: using Microsoft.ApplicationServer.Caching;
2: using System.Collections.Generic;
3:
4: public class CacheUtil
5: {
6: private static DataCacheFactory _factory = null;
7: private static DataCache _cache = null;
8:
9: public static DataCache GetCache()
10: {
11: if (_cache != null)
12: return _cache;
13:
14: //Define Array for 1 Cache Host
15: List<DataCacheServerEndpoint> servers = new List<DataCacheServerEndpoint>(1);
16:
17: //Specify Cache Host Details
18: // Parameter 1 = host name
19: // Parameter 2 = cache port number
20: servers.Add(new DataCacheServerEndpoint("mymachine", 22233));
21:
22: //Create cache configuration
23: DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration();
24:
25: //Set the cache host(s)
26: configuration.Servers = servers;
27:
28: //Set default properties for local cache (local cache disabled)
29: configuration.LocalCacheProperties = new DataCacheLocalCacheProperties();
30:
31: //Disable tracing to avoid informational/verbose messages on the web page
32: DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off);
33:
34: //Pass configuration settings to cacheFactory constructor
35: _factory = new DataCacheFactory(configuration);
36:
37: //Get reference to named cache called "default"
38: _cache = _factory.GetCache("default");
39:
40: return _cache;
41: }
42: }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。