Example #1
0
        public RedisCacheStore(RedisConfiguration configuration, IRedisConnectionFactory connectionFactory, IJsonSerializer serializer)
        {
            // TODO: (core) Build versionStr from SmartstoreVersion class
            var versionStr = "5.0.0";

            // Don't try to deserialize values created with older app versions (could be incompatible)
            _cachePrefix = "cache." + versionStr + ":";
            _keyPrefix   = BuildCacheKey("");

            _configuration     = configuration;
            _connectionFactory = connectionFactory;
            _multiplexer       = _connectionFactory.GetConnection(configuration.ConnectionStrings.Cache ?? configuration.ConnectionStrings.Default);
            _messageBus        = _connectionFactory.GetMessageBus(configuration.ConnectionStrings.Bus ?? configuration.ConnectionStrings.Default);
            _serializer        = serializer;

            // Subscribe to key events triggered by Redis on item expiration
            _messageBus.SubscribeToKeyEvent("expired", OnRedisKeyEvent, false);
            _messageBus.SubscribeToKeyEvent("evicted", OnRedisKeyEvent, false);
        }