/// <summary> /// Configures cache manager logging to use a <c>Microsoft.Extensions.Logging.ILoggerFactory</c> /// which gets resolved from the <paramref name="serviceCollection"/>. /// </summary> /// <param name="part">The builder part.</param> /// <param name="serviceCollection">The services collection.</param> /// <returns>The builder.</returns> public static ConfigurationBuilderCachePart WithMicrosoftLogging(this ConfigurationBuilderCachePart part, IServiceCollection serviceCollection) { NotNull(part, nameof(part)); NotNull(serviceCollection, nameof(serviceCollection)); return(part.WithLogging(typeof(MicrosoftLoggerFactoryAdapter), new Func <ILoggerFactory>(() => GetLoggerFactory(serviceCollection)))); }
/// <summary> /// Adds a <see cref="BucketCacheHandle{TCacheValue}"/> with the required name. /// <para> /// This handle requires a Couchbase <see cref="ClientConfiguration"/> to be defined with /// the <paramref name="couchbaseConfigurationKey"/> matching the configuration's key. /// </para> /// </summary> /// <param name="part">The builder part.</param> /// <param name="couchbaseConfigurationKey"> /// The Couchbase configuration identifier will be used as name for the cache handle and to /// retrieve the connection configuration. /// </param> /// <param name="bucketName"> /// The name of the Couchbase bucket which should be used by the cache handle. /// </param> /// <param name="isBackplaneSource"> /// Set this to true if this cache handle should be the source of the backplane. /// <para>This setting will be ignored if no backplane is configured.</para> /// </param> /// <returns>The part.</returns> /// <exception cref="System.ArgumentNullException">If bucketName is null.</exception> /// <exception cref="ArgumentNullException"> /// Thrown if handleName or handleType are null. /// </exception> public static ConfigurationBuilderCacheHandlePart WithCouchbaseCacheHandle(this ConfigurationBuilderCachePart part, string couchbaseConfigurationKey, string bucketName, bool isBackplaneSource) { NotNull(part, nameof(part)); NotNullOrWhiteSpace(bucketName, nameof(bucketName)); return(part.WithHandle(typeof(BucketCacheHandle <>), couchbaseConfigurationKey + ":" + bucketName, isBackplaneSource)); }
/// <summary> /// Adds a <see cref="MemcachedCacheHandle{TCacheValue}"/> using the <paramref name="clientConfiguration"/> to setup a <see cref="MemcachedClient"/> instance. /// </summary> /// <param name="part">The builder part.</param> /// <param name="clientConfiguration">The <see cref="MemcachedClientConfiguration"/> to use to create the <see cref="MemcachedClient"/> for this cache handle.</param> /// <param name="isBackplaneSource"> /// Set this to true if this cache handle should be the source of the backplane. /// <para>This setting will be ignored if no backplane is configured.</para> /// </param> /// <returns>The part.</returns> /// <exception cref="System.ArgumentNullException"> /// Thrown if <paramref name="clientConfiguration"/> is null. /// </exception> public static ConfigurationBuilderCacheHandlePart WithMemcachedCacheHandle(this ConfigurationBuilderCachePart part, MemcachedClientConfiguration clientConfiguration, bool isBackplaneSource = true) { NotNull(part, nameof(part)); NotNull(clientConfiguration, nameof(clientConfiguration)); return(part.WithHandle(typeof(MemcachedCacheHandle <>), Guid.NewGuid().ToString(), isBackplaneSource, clientConfiguration)); }
/// <summary> /// Adds an already configured <see cref="ICluster" /> for the given key. Use this in case you want to use the <paramref name="cluster" /> outside of CacheManager, too /// and you want to share this instance. /// <para> /// Use <paramref name="configurationKey" /> in <see cref="WithCouchbaseCacheHandle(ConfigurationBuilderCachePart, string, string, bool)" /> (or similar overloads) /// to have the cache handle use this configuration. /// </para><para> /// If your cluster requires authentication, you might have to configure <c>cluster.Authenticate(...)</c>. /// </para> /// </summary> /// <param name="part">The part.</param> /// <param name="configurationKey">The configuration key.</param> /// <param name="cluster">The <see cref="ICluster" />.</param> /// <returns> /// The configuration builder. /// <exception cref="System.ArgumentNullException">If <paramref name="configurationKey" /> or <paramref name="cluster" /> is null.</exception> /// </returns> public static ConfigurationBuilderCachePart WithCouchbaseCluster(this ConfigurationBuilderCachePart part, string configurationKey, ICluster cluster) { NotNullOrWhiteSpace(configurationKey, nameof(configurationKey)); NotNull(cluster, nameof(cluster)); CouchbaseConfigurationManager.AddCluster(configurationKey, cluster); return(part); }
/// <summary> /// Adds a <see cref="ClientConfiguration"/> for the given key. /// <para>The key will be matched with the Couchbase cache handle name.</para> /// </summary> /// <param name="part">The part.</param> /// <param name="configurationKey">The key which has to match with the cache handle name.</param> /// <param name="config">The Couchbase configuration object.</param> /// <returns>The configuration builder.</returns> /// <exception cref="System.ArgumentNullException">If key or config are null.</exception> public static ConfigurationBuilderCachePart WithCouchbaseConfiguration(this ConfigurationBuilderCachePart part, string configurationKey, ClientConfiguration config) { NotNullOrWhiteSpace(configurationKey, nameof(configurationKey)); NotNull(config, nameof(config)); CouchbaseConfigurationManager.AddConfiguration(configurationKey, config); return(part); }
/// <summary> /// Add a <see cref="RedisCacheHandle"/> with the required name. /// <para> /// This handle requires a redis configuration to be defined with the /// <paramref name="redisConfigurationId"/> matching the configuration's id. /// </para> /// </summary> /// <param name="part">The builder part.</param> /// <param name="redisConfigurationId"> /// The redis configuration identifier will be used as name for the cache handle and to /// retrieve the connection configuration. /// </param> /// <param name="isBackPlateSource"> /// Set this to true if this cache handle should be the source of the back plate. /// <para>This setting will be ignored if no back plate is configured.</para> /// </param> /// <returns>The part.</returns> /// <exception cref="ArgumentNullException"> /// Thrown if handleName or handleType are null. /// </exception> public static ConfigurationBuilderCacheHandlePart WithRedisCacheHandle(this ConfigurationBuilderCachePart part, string redisConfigurationId, bool isBackPlateSource) { if (part == null) { throw new ArgumentNullException("part"); } return(part.WithHandle(typeof(RedisCacheHandle <>), redisConfigurationId, isBackPlateSource)); }
/// <summary> /// Adds a redis configuration with the given <paramref name="configurationKey"/>. /// </summary> /// <param name="part">The builder instance.</param> /// <param name="configurationKey"> /// The configuration key which can be used to refernce this configuration by a redis cache handle or backplate. /// </param> /// <param name="connectionString">The redis connection string.</param> /// <returns>The configuration builder.</returns> /// <exception cref="System.ArgumentNullException"> /// If <paramref name="configurationKey"/> or <paramref name="connectionString"/> are null. /// </exception> public static ConfigurationBuilderCachePart WithRedisConfiguration(this ConfigurationBuilderCachePart part, string configurationKey, string connectionString) { NotNullOrWhiteSpace(configurationKey, nameof(configurationKey)); NotNullOrWhiteSpace(connectionString, nameof(connectionString)); RedisConfigurations.AddConfiguration(new RedisConfiguration(configurationKey, connectionString)); return(part); }
/// <summary> /// Configures the back plate for the cache manager. /// <para> /// The <paramref name="redisConfigurationId"/> is used to define the redis configuration, /// the back plate should use to connect to the redis server. /// </para> /// <para> /// If a back plate is defined, at least one cache handle must be marked as back plate /// source. The cache manager then will try to synchronize multiple instances of the same configuration. /// </para> /// </summary> /// <param name="part">The part.</param> /// <param name="redisConfigurationId"> /// The id of the configuration the back plate should use. /// </param> /// <returns>The builder instance.</returns> public static ConfigurationBuilderCachePart WithRedisBackPlate(this ConfigurationBuilderCachePart part, string redisConfigurationId) { if (part == null) { throw new ArgumentNullException("part"); } return(part.WithBackPlate <RedisCacheBackPlate>(redisConfigurationId)); }
/// <summary> /// Adds a <see cref="BucketCacheHandle{TCacheValue}"/> with the required name. /// <para> /// This handle requires a Couchbase <see cref="ClientConfiguration"/> to be defined with /// the <paramref name="couchbaseConfigurationKey"/> matching the configuration's key. /// </para> /// </summary> /// <param name="part">The builder part.</param> /// <param name="couchbaseConfigurationKey"> /// The Couchbase configuration identifier will be used as name for the cache handle and to /// retrieve the connection configuration. /// </param> /// <param name="isBackPlateSource"> /// Set this to true if this cache handle should be the source of the back plate. /// <para>This setting will be ignored if no back plate is configured.</para> /// </param> /// <returns>The part.</returns> /// <exception cref="ArgumentNullException"> /// Thrown if handleName or handleType are null. /// </exception> public static ConfigurationBuilderCacheHandlePart WithCouchbaseCacheHandle( this ConfigurationBuilderCachePart part, string couchbaseConfigurationKey, bool isBackPlateSource) { NotNull(part, nameof(part)); return(part.WithHandle(typeof(BucketCacheHandle <>), couchbaseConfigurationKey, isBackPlateSource)); }
/// <summary> /// Add a <see cref="MemcachedCacheHandle"/> with the required name. /// </summary> /// <param name="part">The builder part.</param> /// <param name="handleName">The name to be used for the cache handle.</param> /// <param name="isBackPlateSource"> /// Set this to true if this cache handle should be the source of the back plate. /// <para>This setting will be ignored if no back plate is configured.</para> /// </param> /// <returns>The part.</returns> /// <exception cref="ArgumentNullException"> /// Thrown if handleName or handleType are null. /// </exception> public static ConfigurationBuilderCacheHandlePart WithMemcachedCacheHandle(this ConfigurationBuilderCachePart part, string handleName, bool isBackPlateSource) { if (part == null) { throw new ArgumentNullException("part"); } return(part.WithHandle(typeof(MemcachedCacheHandle <>), handleName, isBackPlateSource)); }
/// <summary> /// Add a <see cref="BucketCacheHandle"/> with the required name. /// <para> /// This handle requires a Couchbase <see cref="ClientConfiguration"/> to be defined with /// the <paramref name="couchbaseConfigurationKey"/> matching the configuration's key. /// </para> /// </summary> /// <param name="part">The builder part.</param> /// <param name="couchbaseConfigurationKey"> /// The Couchbase configuration identifier will be used as name for the cache handle and to /// retrieve the connection configuration. /// </param> /// <param name="isBackPlateSource"> /// Set this to true if this cache handle should be the source of the back plate. /// <para>This setting will be ignored if no back plate is configured.</para> /// </param> /// <returns>The part.</returns> /// <exception cref="ArgumentNullException"> /// Thrown if handleName or handleType are null. /// </exception> public static ConfigurationBuilderCacheHandlePart WithCouchbaseCacheHandle(this ConfigurationBuilderCachePart part, string couchbaseConfigurationKey, bool isBackPlateSource) { if (part == null) { throw new ArgumentNullException("part"); } return(part.WithHandle(typeof(BucketCacheHandle <>), couchbaseConfigurationKey, isBackPlateSource)); }
public static ConfigurationBuilderCachePart WithMicrosoftLogging(this ConfigurationBuilderCachePart part, Action <ILoggerFactory> factory) { NotNull(part, nameof(part)); NotNull(factory, nameof(factory)); var externalFactory = new LoggerFactory(); factory(externalFactory); return(part.WithLogging(typeof(MicrosoftLoggerFactoryAdapter), externalFactory)); }
/// <summary> /// Adds a redis configuration with the given <paramref name="configurationKey"/>. /// </summary> /// <param name="part">The builder instance.</param> /// <param name="configurationKey"> /// The configuration key which can be used to refernce this configuration by a redis cache handle or backplane. /// </param> /// <param name="connectionString">The redis connection string.</param> /// <param name="database">The redis database to be used.</param> /// <param name="enableKeyspaceNotifications"> /// Enables keyspace notifications to react on eviction/expiration of items. /// Make sure that all servers are configured correctly and 'notify-keyspace-events' is at least set to 'Exe', otherwise CacheManager will not retrieve any events. /// See <see href="https://redis.io/topics/notifications#configuration"/> for configuration details. /// </param> /// <returns>The configuration builder.</returns> /// <exception cref="System.ArgumentNullException"> /// If <paramref name="configurationKey"/> or <paramref name="connectionString"/> are null. /// </exception> public static ConfigurationBuilderCachePart WithRedisConfiguration(this ConfigurationBuilderCachePart part, string configurationKey, string connectionString, int database = 0, bool enableKeyspaceNotifications = false) { NotNullOrWhiteSpace(configurationKey, nameof(configurationKey)); NotNullOrWhiteSpace(connectionString, nameof(connectionString)); RedisConfigurations.AddConfiguration(new RedisConfiguration(configurationKey, connectionString, database, enableKeyspaceNotifications)); return(part); }
/// <summary> /// Builds a <c>CacheManagerConfiguration</c> which can be used to create a new cache /// manager instance. /// <para> /// Pass the configuration to <c>CacheFactory.FromConfiguration</c> to create a valid cache manager. /// </para> /// </summary> /// <param name="settings"> /// The configuration settings to define the cache handles and other properties. /// </param> /// <returns>The <c>CacheManagerConfiguration</c>.</returns> public static CacheManagerConfiguration BuildConfiguration(Action <ConfigurationBuilderCachePart> settings) { NotNull(settings, nameof(settings)); var part = new ConfigurationBuilderCachePart(); settings(part); return(part.Configuration); }
/// <summary> /// <para>Instantiates a cache manager using the inline configuration defined by <paramref name="settings"/>.</para> /// </summary> /// <example> /// The following example show how to build a <c>CacheManagerConfiguration</c> and then /// using the <c>CacheFactory</c> to create a new cache manager instance. /// <code> /// <![CDATA[ /// var cache = CacheFactory.Build("myCacheName", settings => /// { /// settings /// .WithUpdateMode(CacheUpdateMode.Up) /// .WithDictionaryHandle() /// .EnablePerformanceCounters() /// .WithExpiration(ExpirationMode.Sliding, TimeSpan.FromSeconds(10)); /// }); /// /// cache.Add("key", "value"); /// ]]> /// </code> /// </example> /// <param name="cacheName">The name of the cache manager instance.</param> /// <param name="settings"> /// The configuration. Use the settings element to configure the cache manager instance, add /// cache handles and also to configure the cache handles in a fluent way. /// </param> /// <typeparam name="TCacheValue">The type of the cache item value.</typeparam> /// <returns>The cache manager instance with cache item type being <c>TCacheValue</c>.</returns> /// <seealso cref="ICacheManager{TCacheValue}"/> /// <exception cref="System.ArgumentNullException"> /// Thrown if the <paramref name="cacheName"/> or <paramref name="settings"/> is null. /// </exception> /// <exception cref="System.InvalidOperationException"> /// Thrown on certain configuration errors related to the cache handles. /// </exception> public static ICacheManager <TCacheValue> Build <TCacheValue>(string cacheName, Action <ConfigurationBuilderCachePart> settings) { NotNull(settings, nameof(settings)); var part = new ConfigurationBuilderCachePart(); settings(part); return(new BaseCacheManager <TCacheValue>(cacheName, part.Configuration)); }
/// <summary> /// Adds a redis configuration with the given <paramref name="configurationKey"/>. /// </summary> /// <param name="part">The builder instance.</param> /// <param name="configurationKey"> /// The configuration key which can be used to refernce this configuration by a redis cache handle or backplate. /// </param> /// <param name="configuration">The redis configuration object.</param> /// <returns>The configuration builder.</returns> /// <exception cref="System.ArgumentNullException">If <paramref name="configuration"/> or <paramref name="configurationKey"/> are null.</exception> public static ConfigurationBuilderCachePart WithRedisConfiguration(this ConfigurationBuilderCachePart part, string configurationKey, Action <RedisConfigurationBuilder> configuration) { NotNull(configuration, nameof(configuration)); var builder = new RedisConfigurationBuilder(configurationKey); configuration(builder); RedisConfigurations.AddConfiguration(builder.Build()); return(part); }
/// <summary> /// Builds a <see cref="CacheManagerConfiguration"/> which can be used to create a new cache /// manager instance. /// <para> /// Pass the configuration to <see cref="CacheFactory.FromConfiguration{TCacheValue}(CacheManagerConfiguration)"/> /// to create a valid cache manager. /// </para> /// </summary> /// <param name="name">The name of the cache manager.</param> /// <param name="settings"> /// The configuration settings to define the cache handles and other properties. /// </param> /// <returns>The <see cref="CacheManagerConfiguration"/>.</returns> public static CacheManagerConfiguration BuildConfiguration(string name, Action <ConfigurationBuilderCachePart> settings) { NotNullOrWhiteSpace(name, nameof(name)); NotNull(settings, nameof(settings)); var part = new ConfigurationBuilderCachePart(); settings(part); part.Configuration.Name = name; return(part.Configuration); }
/// <summary> /// Configures cache manager logging to use a <c>Microsoft.Extensions.Logging.ILoggerFactory</c> /// which gets resolved from the <paramref name="serviceCollection"/>. /// </summary> /// <param name="part">The builder part.</param> /// <param name="serviceCollection">The services collection.</param> /// <returns>The builder.</returns> public static ConfigurationBuilderCachePart WithMicrosoftLogging(this ConfigurationBuilderCachePart part, IServiceCollection serviceCollection) { NotNull(part, nameof(part)); NotNull(serviceCollection, nameof(serviceCollection)); var loggerFactory = GetLoggerFactory(serviceCollection); EnsureNotNull(loggerFactory, "No instance of ILoggerFactory found in {0}.", nameof(serviceCollection)); return(WithMicrosoftLogging(part, loggerFactory)); }
/// <summary> /// Builds a <c>CacheManagerConfiguration</c> which can be used to create a new cache /// manager instance. /// <para> /// Pass the configuration to <c>CacheFactory.FromConfiguration</c> to create a valid cache manager. /// </para> /// </summary> /// <param name="settings"> /// The configuration settings to define the cache handles and other properties. /// </param> /// <returns>The <c>CacheManagerConfiguration</c>.</returns> public static CacheManagerConfiguration BuildConfiguration(Action <ConfigurationBuilderCachePart> settings) { if (settings == null) { throw new ArgumentNullException("settings"); } var part = new ConfigurationBuilderCachePart(); settings(part); return(part.Configuration); }
/// <summary> /// <para>Instantiates a cache manager using the inline configuration defined by <paramref name="settings"/>.</para> /// </summary> /// <example> /// The following example show how to build a <c>CacheManagerConfiguration</c> and then /// using the <c>CacheFactory</c> to create a new cache manager instance. /// <code> /// <![CDATA[ /// var cache = CacheFactory.Build("myCacheName", settings => /// { /// settings /// .WithUpdateMode(CacheUpdateMode.Up) /// .WithHandle<DictionaryCacheHandle>("handle1") /// .EnablePerformanceCounters() /// .WithExpiration(ExpirationMode.Sliding, TimeSpan.FromSeconds(10)); /// }); /// /// cache.Add("key", "value"); /// ]]> /// </code> /// </example> /// <param name="cacheName">The name of the cache manager instance.</param> /// <param name="settings"> /// The configuration. Use the settings element to configure the cache manager instance, add /// cache handles and also to configure the cache handles in a fluent way. /// </param> /// <typeparam name="TCacheValue">The type of the cache item value.</typeparam> /// <returns>The cache manager instance with cache item type being <c>TCacheValue</c>.</returns> /// <seealso cref="ICacheManager{TCacheValue}"/> /// <exception cref="System.ArgumentNullException"> /// Thrown if the <paramref name="cacheName"/> or <paramref name="settings"/> is null. /// </exception> /// <exception cref="System.InvalidOperationException"> /// Thrown on certain configuration errors related to the cache handles. /// </exception> public static ICacheManager <TCacheValue> Build <TCacheValue>(string cacheName, Action <ConfigurationBuilderCachePart> settings) { if (settings == null) { throw new ArgumentNullException("settings"); } var part = new ConfigurationBuilderCachePart(); settings(part); return(new BaseCacheManager <TCacheValue>(cacheName, part.Configuration)); }
/// <summary> /// Adds a redis configuration. /// </summary> /// <param name="part">The part.</param> /// <param name="configurationKey"> /// The configuration key which has to match with the cache handle name. /// </param> /// <param name="config">The redis configuration object.</param> /// <returns>The configuration builder.</returns> /// <exception cref="System.ArgumentNullException">If config is null.</exception> public static ConfigurationBuilderCachePart WithRedisConfiguration(this ConfigurationBuilderCachePart part, string configurationKey, Action <RedisConfigurationBuilder> config) { if (config == null) { throw new ArgumentNullException("config"); } var builder = new RedisConfigurationBuilder(configurationKey); config(builder); RedisConfigurations.AddConfiguration(builder.Build()); return(part); }
/// <summary> /// Configures the cache manager to use the <code>DataContract</code> based cache serializer in binary format. /// </summary> /// <param name="part">The configuration part.</param> /// <param name="serializerSettings">Settings for the serializer.</param> /// <returns>The builder instance.</returns> public static ConfigurationBuilderCachePart WithDataContractBinarySerializer(this ConfigurationBuilderCachePart part, DataContractSerializerSettings serializerSettings = null) { NotNull(part, nameof(part)); if (serializerSettings == null) { return(part.WithSerializer(typeof(DataContractBinaryCacheSerializer))); } else { return(part.WithSerializer(typeof(DataContractBinaryCacheSerializer), serializerSettings)); } }
public static ConfigurationBuilderCachePart WithRedisConfiguration(this ConfigurationBuilderCachePart part, string configurationKey, IConnectionMultiplexer redisClient, int database = 0) { NotNullOrWhiteSpace(configurationKey, nameof(configurationKey)); NotNull(redisClient, nameof(redisClient)); var connectionString = redisClient.Configuration; part.WithRedisConfiguration(configurationKey, connectionString, database); RedisConnectionManager.AddConnection(connectionString, redisClient); return(part); }
/// <summary> /// Add a <see cref="BucketCacheHandle"/> with the required name. /// <para> /// This handle requires a Couchbase <see cref="ClientConfiguration"/> to be defined with /// the <paramref name="couchbaseConfigurationKey"/> matching the configuration's key. /// </para> /// </summary> /// <param name="part">The builder part.</param> /// <param name="couchbaseConfigurationKey"> /// The Couchbase configuration identifier will be used as name for the cache handle and to /// retrieve the connection configuration. /// </param> /// <param name="bucketName"> /// The name of the Couchbase bucket which should be used by the cache handle. /// </param> /// <param name="isBackPlateSource"> /// Set this to true if this cache handle should be the source of the back plate. /// <para>This setting will be ignored if no back plate is configured.</para> /// </param> /// <returns>The part.</returns> /// <exception cref="System.ArgumentNullException">If bucketName is null.</exception> /// <exception cref="ArgumentNullException"> /// Thrown if handleName or handleType are null. /// </exception> public static ConfigurationBuilderCacheHandlePart WithCouchbaseCacheHandle(this ConfigurationBuilderCachePart part, string couchbaseConfigurationKey, string bucketName, bool isBackPlateSource) { if (part == null) { throw new ArgumentNullException("part"); } if (string.IsNullOrWhiteSpace(bucketName)) { throw new ArgumentNullException("bucketName"); } return(part.WithHandle(typeof(BucketCacheHandle <>), couchbaseConfigurationKey + ":" + bucketName, isBackPlateSource)); }
/// <summary> /// Adds a <see cref="ClientConfiguration"/> for the given key. /// <para>The key will be matched with the Couchbase cache handle name.</para> /// </summary> /// <param name="part">The part.</param> /// <param name="key">The key which has to match with the cache handle name.</param> /// <param name="config">The Couchbase configuration object.</param> /// <returns>The configuration builder.</returns> /// <exception cref="System.ArgumentNullException">If key or config are null.</exception> public static ConfigurationBuilderCachePart WithCouchbaseConfiguration(this ConfigurationBuilderCachePart part, string key, ClientConfiguration config) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException("key"); } if (config == null) { throw new ArgumentNullException("config"); } CouchbaseConfigurationManager.AddConfiguration(key, config); return(part); }
/// <summary> /// Adds a <see cref="BucketCacheHandle{TCacheValue}" /> using the configuration referenced via <paramref name="couchbaseConfigurationKey" />. /// <para> /// The cache handle needs configuration specific to Couchbase, see remarks for details. /// </para> /// </summary> /// <param name="part">The builder part.</param> /// <param name="couchbaseConfigurationKey">The configuration identifier.</param> /// <param name="bucketName">The name of the Couchbase bucket which should be used by the cache handle.</param> /// <param name="isBackplaneSource">Set this to <c>true</c> if this cache handle should be the source of the backplane. This setting will be ignored if no backplane is configured.</param> /// <returns> /// The part. /// </returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="bucketName" /> or <paramref name="couchbaseConfigurationKey" /> is null.</exception> /// <remarks> /// The Couchbase cache handle requires configuration which can be defined via: /// <list type="bullet"><item> /// <term> /// A configuration with a matching <paramref name="couchbaseConfigurationKey" /> being added via <see cref="WithCouchbaseConfiguration(ConfigurationBuilderCachePart, string, ClientConfiguration)" />. /// </term></item> /// <item><term> /// A cluster with a matching <paramref name="couchbaseConfigurationKey" /> being added via <see cref="WithCouchbaseCluster(ConfigurationBuilderCachePart, string, ICluster)" />. /// </term></item> /// <item><term> /// A <c>CouchbaseClientSection</c> configured in <c>App/Web.config</c> (only available on full .NET Framework). /// </term></item> /// <item><term> /// Or, the cluster has been configured via <see cref="ClusterHelper" /> and CacheManager will use the cluster returned by <see cref="ClusterHelper.Get" />. /// Anyways, this will be the last fallback which, if nothing has been configured at all, will fall back to the default server endpoint on <c>127.0.0.1:8091</c>. /// </term></item> /// </list> /// <para> /// If your cluster requires authentication, use either the <see cref="ClusterHelper" /> or add a <see cref="ICluster" /> with valid authentication via <c>cluster.Authenticate(...)</c>. /// </para> /// </remarks> public static ConfigurationBuilderCacheHandlePart WithCouchbaseCacheHandle( this ConfigurationBuilderCachePart part, string couchbaseConfigurationKey, string bucketName = CouchbaseConfigurationManager.DefaultBucketName, bool isBackplaneSource = true) { NotNull(part, nameof(part)); NotNullOrWhiteSpace(bucketName, nameof(bucketName)); return(part.WithHandle(typeof(BucketCacheHandle <>), couchbaseConfigurationKey, isBackplaneSource, new BucketCacheHandleAdditionalConfiguration() { BucketName = bucketName })); }
/// <summary> /// Adds a redis configuration. /// </summary> /// <param name="part">The part.</param> /// <param name="configurationKey"> /// The configuration key which has to match with the cache handle name. /// </param> /// <param name="connectionString">The redis connection string.</param> /// <returns>The configuration builder.</returns> /// <exception cref="System.ArgumentNullException"> /// If configurationKey or connectionString are null. /// </exception> public static ConfigurationBuilderCachePart WithRedisConfiguration(this ConfigurationBuilderCachePart part, string configurationKey, string connectionString) { if (string.IsNullOrWhiteSpace(configurationKey)) { throw new ArgumentNullException("configurationKey"); } if (string.IsNullOrWhiteSpace(connectionString)) { throw new ArgumentNullException("connectionString"); } RedisConfigurations.AddConfiguration(new RedisConfiguration(configurationKey, connectionString)); return(part); }
/// <summary> /// Builds a <see cref="CacheManagerConfiguration"/> which can be used to create a new cache /// manager instance. /// <para> /// Pass the configuration to <see cref="CacheFactory.FromConfiguration{TCacheValue}(CacheManagerConfiguration)"/> /// to create a valid cache manager. /// </para> /// </summary> /// <param name="settings"> /// The configuration settings to define the cache handles and other properties. /// </param> /// <returns>The <see cref="CacheManagerConfiguration"/>.</returns> public static CacheManagerConfiguration BuildConfiguration(Action<ConfigurationBuilderCachePart> settings) { NotNull(settings, nameof(settings)); var part = new ConfigurationBuilderCachePart(); settings(part); return part.Configuration; }
internal ConfigurationBuilderCacheHandlePart(CacheHandleConfiguration cfg, ConfigurationBuilderCachePart parentPart) { this.Configuration = cfg; this.parent = parentPart; }
/// <summary> /// Builds a <see cref="CacheManagerConfiguration"/> which can be used to create a new cache /// manager instance. /// <para> /// Pass the configuration to <see cref="CacheFactory.FromConfiguration{TCacheValue}(CacheManagerConfiguration)"/> /// to create a valid cache manager. /// </para> /// </summary> /// <param name="name">The name of the cache manager.</param> /// <param name="settings"> /// The configuration settings to define the cache handles and other properties. /// </param> /// <returns>The <see cref="CacheManagerConfiguration"/>.</returns> public static CacheManagerConfiguration BuildConfiguration(string name, Action<ConfigurationBuilderCachePart> settings) { NotNullOrWhiteSpace(name, nameof(name)); NotNull(settings, nameof(settings)); var part = new ConfigurationBuilderCachePart(); settings(part); part.Configuration.Name = name; return part.Configuration; }
/// <summary> /// Configures the cache manager to use the Newtonsoft.Json based cache serializer. /// </summary> /// <param name="part">The part.</param> /// <param name="serializationSettings">Settings to be used during serialization.</param> /// <param name="deserializationSettings">Settings to be used during deserialization.</param> /// <returns>The builder instance.</returns> public static ConfigurationBuilderCachePart WithJsonSerializer(this ConfigurationBuilderCachePart part, JsonSerializerSettings serializationSettings, JsonSerializerSettings deserializationSettings) { NotNull(part, nameof(part)); return(part.WithSerializer(typeof(JsonCacheSerializer), serializationSettings, deserializationSettings)); }
/// <summary> /// Configures the cache manager to use the Newtonsoft.Json based cache serializer. /// </summary> /// <param name="part">The part.</param> /// <returns>The builder instance.</returns> public static ConfigurationBuilderCachePart WithJsonSerializer(this ConfigurationBuilderCachePart part) { NotNull(part, nameof(part)); return(part.WithSerializer(typeof(JsonCacheSerializer))); }
/// <summary> /// Adds a <see cref="MemcachedCacheHandle{TCacheValue}"/>. The <paramref name="configurationName"/> must match with cache configured via enyim configuration section. /// </summary> /// <param name="part">The builder part.</param> /// <param name="configurationName">The configuration name.</param> /// <param name="client">The <see cref="MemcachedClient"/> to use for this cache handle.</param> /// <param name="isBackplaneSource"> /// Set this to true if this cache handle should be the source of the backplane. /// <para>This setting will be ignored if no backplane is configured.</para> /// </param> /// <returns>The part.</returns> /// <exception cref="System.ArgumentNullException"> /// Thrown if <paramref name="client"/> is null. /// </exception> public static ConfigurationBuilderCacheHandlePart WithMemcachedCacheHandle(this ConfigurationBuilderCachePart part, string configurationName, MemcachedClient client, bool isBackplaneSource = true) { NotNull(part, nameof(part)); return(part.WithHandle(typeof(MemcachedCacheHandle <>), configurationName, isBackplaneSource, client)); }