Configuration Overview
Configuration values for the ScaleOut Client library control two types of settings:
- How to connect to instances of the ScaleOut service.
- The default policies (timeouts, locking behavior, etc.) for a named cache. This configuration is optional and can be specified or overridden by code at runtime.
Configuration Providers
Both traditional .NET Framework config files (web.config, app.config) and .NET Core's configuration API are supported.
If a LegacyXmlConfiguration instance is passed as
an argument to the CacheBuilder constructor, the library will attempt
to load configuration settings from a traditional .NET Framework XML
config file. If no app/web.config is found or the XML is malformed, a
System.Configuration.ConfigurationErrorsException
will be thrown.
// Use .NET Framework web.config/app.config:
var cb = new CacheBuilder<string, string>("customers",
"bootstrapGateways=localhost:721",
new LegacyXmlConfiguration("customerCacheConfig"));
Otherwise, pass an IConfiguration argument to the CacheBuilder to use .NET Core's configuration API. Use the GetSection method to pass the key to the configuration section containing the cache's default policy values:
// Use a .NET Core Configuration API provider:
var configBuilder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
IConfiguration netCoreConfig = configBuilder.Build();
var cb = new CacheBuilder<string, string>(
"customers",
"bootstrapGateways=localhost:721",
netCoreConfig.GetSection("Scaleout.Client:customerCacheConfig")
);
Tip
In ASP.NET Core, an IConfiguration instance is built on your behalf
and is available as a property in your application's Startup
class.
Typical Configuration
The .NET Core Configuration API allows a number of different providers to act as configuration sources for an application, including config files (appsettings.json), environment variables, command line arguments, and in-memory .NET objects. This topic will focus on typical JSON file configuration, but any provider could be used.
{
"Scaleout.Client": {
"customerCacheConfig": {
"ExclusiveLockRetryIntervalMS": 5,
"Timeout": "00:45:00",
"ClientCacheEviction": "LRU",
"ClientCacheCapacity": 1000,
"CoherencyInterval": "00:00:00"
},
"productCacheConfig": {
"ExclusiveLockRetryIntervalMS": 5,
"Timeout": "2.00:00:00",
"ClientCacheEviction": "LRU",
"ClientCacheCapacity": 250,
"CoherencyInterval": "00:01:00"
}
}
}