Ejemplo n.º 1
0
 /// <summary>
 /// Configures the cache manager to use the <code>ProtoBuf</code> based cache serializer.
 /// </summary>
 /// <param name="part">The configuration part.</param>
 /// <returns>The builder instance.</returns>
 public static ConfigurationBuilderCachePart WithProtoBufSerializer(
     this ConfigurationBuilderCachePart part,
     RecyclableMemoryStreamManager recyclableMemoryStreamManager)
 {
     Guard.NotNull <ConfigurationBuilderCachePart>(part, nameof(part));
     return(part.WithSerializer(typeof(ProtoBufSerializer), recyclableMemoryStreamManager));
 }
        public static ConfigurationBuilderCachePart TestSerializer(this ConfigurationBuilderCachePart part, Serializer serializer)
        {
            switch (serializer)
            {
            case Serializer.Binary:
                break;

            case Serializer.GzJson:
                part.WithGzJsonSerializer();
                break;

            case Serializer.Json:
                part.WithJsonSerializer();
                break;

            case Serializer.Proto:
                part.WithProtoBufSerializer();
                break;

            case Serializer.BondBinary:
                part.WithBondCompactBinarySerializer(2048);
                break;
            }
            return(part);
        }
Ejemplo n.º 3
0
 public static ConfigurationBuilderCacheHandlePart WithSQLiteCacheHandle(
     this ConfigurationBuilderCachePart part,
     SQLiteCacheHandleAdditionalConfiguration config)
 => part?.WithHandle(
     typeof(SQLiteCacheHandle <>),
     Guid.NewGuid().ToString(),
     isBackplaneSource: false,
     config);
        /// <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)
        {
            Guard.NotNullOrWhiteSpace(configurationKey, nameof(configurationKey));

            Guard.NotNullOrWhiteSpace(connectionString, nameof(connectionString));

            RedisConfigurations.AddConfiguration(new RedisConfiguration(configurationKey, connectionString, database, enableKeyspaceNotifications));
            return(part);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Configures the cache manager to use the <code>Hyperion</code> based cache serializer.
        /// </summary>
        /// <param name="part">The configuration part.</param>
        /// <param name="serializerSettings">Hyperion serialization settings</param>
        /// <returns>The builder instance.</returns>
        public static ConfigurationBuilderCachePart WithHyperionSerializer(this ConfigurationBuilderCachePart part, HyperionSerializerSettings serializerSettings)
        {
            if (part == null)
            {
                throw new ArgumentNullException(nameof(part));
            }

            return(part.WithSerializer(typeof(HyperionSerializer), serializerSettings));
        }
        /// <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="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)
        {
            Guard.NotNull(configuration, nameof(configuration));

            var builder = new RedisConfigurationBuilder(configurationKey);

            configuration(builder);
            RedisConfigurations.AddConfiguration(builder.Build());
            return(part);
        }
        /// <summary>
        /// Adds an existing <see cref="IConnectionMultiplexer"/> to the cache manager configuration which can be referenced by redis cache handle and/or backplane.
        /// </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="redisClient">The connection multiplexer instance.</param>
        /// <param name="database">The redis database to use for caching.</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="redisClient"/> are null.
        /// </exception>
        public static ConfigurationBuilderCachePart WithRedisConfiguration(this ConfigurationBuilderCachePart part, string configurationKey, IConnectionMultiplexer redisClient, int database = 0, bool enableKeyspaceNotifications = false)
        {
            Guard.NotNullOrWhiteSpace(configurationKey, nameof(configurationKey));

            Guard.NotNull(redisClient, nameof(redisClient));

            var connectionString = redisClient.Configuration;

            part.WithRedisConfiguration(configurationKey, connectionString, database, enableKeyspaceNotifications);

            RedisConnectionManager.AddConnection(connectionString, redisClient);

            return(part);
        }
Ejemplo n.º 8
0
        public static ConfigurationBuilderCachePart TestSerializer(this ConfigurationBuilderCachePart part, Serializer serializer)
        {
            switch (serializer)
            {
            case Serializer.Binary:
                break;

            case Serializer.GzJson:
                part.WithGzJsonSerializer();
                break;

            case Serializer.Json:
                part.WithJsonSerializer();
                break;

            case Serializer.Proto:
                part.WithProtoBufSerializer();
                break;

            case Serializer.BondBinary:
                part.WithBondCompactBinarySerializer(2048);
                break;

            case Serializer.DataContract:
                part.WithDataContractSerializer();
                break;

            case Serializer.DataContractBinary:
                part.WithDataContractBinarySerializer();
                break;

            case Serializer.DataContractGzJson:
                part.WithDataContractGzJsonSerializer();
                break;

            case Serializer.DataContractJson:
                part.WithDataContractJsonSerializer();
                break;

            default:
                throw new InvalidOperationException("Unknown serializer");
            }
            return(part);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Adds a cache handle using <see cref="MemoryCache"/>.
 /// </summary>
 /// <param name="part">The builder part.</param>
 /// <param name="isBackplaneSource">Set this to true if this cache handle should be the source of the backplane.
 /// This setting will be ignored if no backplane is configured.</param>
 /// <returns>
 /// The builder part.
 /// </returns>
 /// <returns>The builder part.</returns>
 public static ConfigurationBuilderCacheHandlePart WithMemoryCacheHandle(this ConfigurationBuilderCachePart part, bool isBackplaneSource = false) => WithMemoryCacheHandle(part, Guid.NewGuid().ToString(), isBackplaneSource, new MemoryCacheOptions());
Ejemplo n.º 10
0
 public static void UseMemoryCache(this ConfigurationBuilderCachePart cacheConfigurationBuilder,
                                   uint expiresInSeconds)
 {
     cacheConfigurationBuilder.WithMicrosoftMemoryCacheHandle()
     .WithExpiration(ExpirationMode.Absolute, TimeSpan.FromSeconds(expiresInSeconds));
 }
 /// <summary>
 /// Adds a <see cref="MemoryCacheHandle{TCacheValue}" /> using a <see cref="MemoryCache"/> instance with the given <paramref name="instanceName"/>.
 /// The named cache instance can be configured via <c>app/web.config</c> <c>system.runtime.caching</c> section.
 /// </summary>
 /// <param name="part">The builder part.</param>
 /// <param name="instanceName">The name to be used for the cache instance.</param>
 /// <param name="isBackplaneSource">Set this to true if this cache handle should be the source of the backplane.
 /// This setting will be ignored if no backplane is configured.</param>
 /// <returns>
 /// The builder part.
 /// </returns>
 /// <exception cref="System.ArgumentNullException">If part is null.</exception>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="instanceName"/> is null.</exception>
 public static ConfigurationBuilderCacheHandlePart WithMemoryCacheHandle(this ConfigurationBuilderCachePart part, string instanceName, bool isBackplaneSource = false) => part?.WithHandle(typeof(MemoryCacheHandle <>), instanceName, isBackplaneSource);
Ejemplo n.º 12
0
 /// <summary>
 /// Adds a cache handle using <see cref="MemoryCache"/>.
 /// The name of the cache instance will be 'default'.
 /// </summary>
 /// <param name="part">The builder part.</param>
 /// <param name="options">The <see cref="MemoryCacheOptions"/> which should be used to initiate or reset this cache.</param>
 /// <returns>The builder part.</returns>
 public static ConfigurationBuilderCacheHandlePart WithMemoryCacheHandle(this ConfigurationBuilderCachePart part, MemoryCacheOptions options) => WithMemoryCacheHandle(part, Guid.NewGuid().ToString(), false, options);
Ejemplo n.º 13
0
 /// <summary>
 /// Adds a cache handle using <see cref="MemoryCache"/>.
 /// </summary>
 /// <param name="part">The builder part.</param>
 /// <param name="instanceName">The name to be used for the cache handle instance.</param>
 /// <param name="options">The <see cref="MemoryCacheOptions"/> which should be used to initiate or reset this cache.</param>
 /// <returns>The builder part.</returns>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="instanceName"/> is null.</exception>
 public static ConfigurationBuilderCacheHandlePart WithMemoryCacheHandle(this ConfigurationBuilderCachePart part, string instanceName, MemoryCacheOptions options) => WithMemoryCacheHandle(part, instanceName, false, options);
Ejemplo n.º 14
0
 /// <summary>
 /// Adds a cache handle using <see cref="MemoryCache"/>.
 /// </summary>
 /// <param name="part">The builder part.</param>
 /// <param name="instanceName">The name to be used for the cache handle instance.</param>
 /// <param name="isBackplaneSource">Set this to true if this cache handle should be the source of the backplane.
 /// This setting will be ignored if no backplane is configured.</param>
 /// <returns>
 /// The builder part.
 /// </returns>
 /// <exception cref="System.ArgumentNullException">If part is null.</exception>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="instanceName"/> is null.</exception>
 public static ConfigurationBuilderCacheHandlePart WithMemoryCacheHandle(this ConfigurationBuilderCachePart part, string instanceName, bool isBackplaneSource = false) => WithMemoryCacheHandle(part, instanceName, isBackplaneSource, new MemoryCacheOptions());
Ejemplo n.º 15
0
        /// <summary>
        /// Configures the cache manager to use the <code>fastJSON</code> based cache serializer with compression.
        /// </summary>
        /// <param name="part">The configuration part.</param>
        /// <returns>The builder instance.</returns>
        public static ConfigurationBuilderCachePart WithGzJsonSerializer(this ConfigurationBuilderCachePart part)
        {
            NotNull(part, nameof(part));

            return(part.WithSerializer(typeof(GzJsonCacheSerializer)));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Configures the cache manager to use the <code>fastJSON</code> based cache serializer with compression.
        /// </summary>
        /// <param name="part">The configuration part.</param>
        /// <param name="fastJsonSettings">The settings to be used during serialization/deserialization.</param>
        /// <returns>The builder instance.</returns>
        public static ConfigurationBuilderCachePart WithGzJsonSerializer(this ConfigurationBuilderCachePart part, JSONParameters fastJsonSettings)
        {
            NotNull(part, nameof(part));

            return(part.WithSerializer(typeof(GzJsonCacheSerializer), fastJsonSettings));
        }
        /// <summary>
        /// Configures a cache backplane for the cache manager.
        /// The <paramref name="redisConfigurationKey"/> is used to find a matching redis configuration.
        /// <para>
        /// If a backplane is defined, at least one cache handle must be marked as backplane
        /// source. The cache manager then will try to synchronize multiple instances of the same configuration.
        /// </para>
        /// </summary>
        /// <param name="part">The builder instance.</param>
        /// <param name="redisConfigurationKey">
        /// The redis configuration key will be used to find a matching redis connection configuration.
        /// </param>
        /// <param name="channelName">The pub sub channel name the backplane should use.</param>
        /// <returns>The builder instance.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="redisConfigurationKey"/> is null.</exception>
        public static ConfigurationBuilderCachePart WithRedisBackplane(this ConfigurationBuilderCachePart part, string redisConfigurationKey, string channelName)
        {
            Guard.NotNull(part, nameof(part));

            return(part.WithBackplane(typeof(RedisCacheBackplane), redisConfigurationKey, channelName));
        }
Ejemplo n.º 18
0
 public static void UseMemoryCache(this ConfigurationBuilderCachePart cacheConfigurationBuilder)
 {
     cacheConfigurationBuilder.WithMicrosoftMemoryCacheHandle();
 }
        /// <summary>
        /// Adds a <see cref="RedisCacheHandle{TCacheValue}"/>.
        /// This handle requires a redis configuration to be defined with the given <paramref name="redisConfigurationKey"/>.
        /// </summary>
        /// <param name="part">The builder instance.</param>
        /// <param name="redisConfigurationKey">
        /// The redis configuration key will be used to find a matching redis connection configuration.
        /// </param>
        /// <param name="isBackplaneSource">
        /// Set this to true if this cache handle should be the source of the backplane.
        /// This setting will be ignored if no backplane is configured.
        /// </param>
        /// <returns>The builder instance.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="redisConfigurationKey"/> is null.</exception>
        public static ConfigurationBuilderCacheHandlePart WithRedisCacheHandle(this ConfigurationBuilderCachePart part, string redisConfigurationKey, bool isBackplaneSource = true)
        {
            Guard.NotNull(part, nameof(part));

            return(part.WithHandle(typeof(RedisCacheHandle <>), redisConfigurationKey, isBackplaneSource));
        }
Ejemplo n.º 20
0
 public static ConfigurationBuilderCacheHandlePart WithParentCache <TCacheValue>(this ConfigurationBuilderCachePart config, ParentCache <TCacheValue> parent)
 => config.WithHandle(typeof(ParentCacheHandle <>), "PraentCache", false, parent);
Ejemplo n.º 21
0
        /// <summary>
        /// Configures the cache manager to use the <code>NetJSON</code> based cache serializer with compression.
        /// </summary>
        /// <param name="part">The configuration part.</param>
        /// <param name="settings">The settings to be used during serialization/deserialization.</param>
        /// <returns>The builder instance.</returns>
        public static ConfigurationBuilderCachePart WithNetJSONJsonSerializer(this ConfigurationBuilderCachePart part, NetJSONSettings settings)
        {
            NotNull(part, nameof(part));

            return(part.WithSerializer(typeof(GzNetJSONCacheSerializer), settings));
        }