Exemplo n.º 1
0
 public CachingCommandDefinition(DbCommandDefinition commandDefinition, CommandTreeFacts commandTreeFacts, CacheTransactionHandler cacheTransactionHandler, CachingPolicy cachingPolicy)
 {
     _commandDefintion        = commandDefinition;
     _commandTreeFacts        = commandTreeFacts;
     _cacheTransactionHandler = cacheTransactionHandler;
     _cachingPolicy           = cachingPolicy;
 }
Exemplo n.º 2
0
        public SmartDbConfiguration()
        {
            IEfDataProvider provider = null;
            try
            {
                provider = (new EfDataProviderFactory(DataSettings.Current).LoadDataProvider()) as IEfDataProvider;
            }
            catch { /* SmartStore is not installed yet! */ }

            if (provider != null)
            {
                base.SetDefaultConnectionFactory(provider.GetConnectionFactory());

                // prepare EntityFramework 2nd level cache
                ICache cache = null;
                try
                {
                    var innerCache = EngineContext.Current.Resolve<Func<Type, SmartStore.Core.Caching.ICache>>();
                    cache = new EfCacheImpl(innerCache(typeof(SmartStore.Core.Caching.StaticCache)));
                }
                catch
                {
                    cache = new InMemoryCache();
                }

                var transactionHandler = new CacheTransactionHandler(cache);
                AddInterceptor(transactionHandler);

                Loaded +=
                  (sender, args) => args.ReplaceService<DbProviderServices>(
                    (s, _) => new CachingProviderServices(s, transactionHandler,
                      new EfCachingPolicy()));
            }
        }
 public CachingCommandDefinition(DbCommandDefinition commandDefinition, CommandTreeFacts commandTreeFacts, CacheTransactionHandler cacheTransactionHandler, CachingPolicy cachingPolicy)
 {
     _commandDefintion = commandDefinition;
     _commandTreeFacts = commandTreeFacts;
     _cacheTransactionHandler = cacheTransactionHandler;
     _cachingPolicy = cachingPolicy;
 }
Exemplo n.º 4
0
        public static void Initialize(ICache cache, CachingPolicy cachingPolicy)
        {
            var transactionHandler = new CacheTransactionHandler(cache);

            DbConfiguration.Loaded +=
                (sender, args) => args.ReplaceService <DbProviderServices>(
                    (dbServices, _) => new CachingProviderServices(dbServices, transactionHandler, cachingPolicy));
            DbInterception.Add(transactionHandler);
        }
Exemplo n.º 5
0
        public Configuration()
        {
            var transactionHandler = new CacheTransactionHandler(E2ETest.Cache);

            AddInterceptor(transactionHandler);

            Loaded +=
                (sender, args) => args.ReplaceService <DbProviderServices>(
                    (s, _) => new CachingProviderServices(s, transactionHandler));
        }
Exemplo n.º 6
0
        public Configuration()
        {
            var transactionHandler = new CacheTransactionHandler(E2ETest.Cache);

            AddInterceptor(transactionHandler);

            Loaded +=
                (sender, args) => args.ReplaceService<DbProviderServices>(
                    (s, _) => new CachingProviderServices(s, transactionHandler));
        }
Exemplo n.º 7
0
        public AppDbConfiguration()
        {
            var transactionHandler = new CacheTransactionHandler(new InMemoryCache());

            AddInterceptor(transactionHandler);

            var cachingPolicy = new CachingPolicy();

            Loaded += (sender, args) => args.ReplaceService<DbProviderServices>(
                        (s, _) => new CachingProviderServices(s, transactionHandler, cachingPolicy));
        }
Exemplo n.º 8
0
        public Configuration()
        {
            var transactionHandler = new CacheTransactionHandler(UnitOfWork.UnitOfWork.Cache);

            AddInterceptor(transactionHandler);

            var cachingPolicy = new CachingPolicy();

            Loaded += (sender, args) => args.ReplaceService<DbProviderServices>((s, _) =>
                new CachingProviderServices(s, transactionHandler, cachingPolicy));
        }
Exemplo n.º 9
0
        public CachingCommand(DbCommand command, CommandTreeFacts commandTreeFacts, CacheTransactionHandler cacheTransactionHandler, CachingPolicy cachingPolicy)
        {
            Debug.Assert(command != null, "command is null");
            Debug.Assert(commandTreeFacts != null, "commandTreeFacts is null");
            Debug.Assert(cacheTransactionHandler != null, "cacheTransactionHandler is null");
            Debug.Assert(cachingPolicy != null, "cachingPolicy is null");

            _command                 = command;
            _commandTreeFacts        = commandTreeFacts;
            _cacheTransactionHandler = cacheTransactionHandler;
            _cachingPolicy           = cachingPolicy;
        }
Exemplo n.º 10
0
        public CachingCommand(DbCommand command, CommandTreeFacts commandTreeFacts, CacheTransactionHandler cacheTransactionHandler, CachingPolicy cachingPolicy)
        {
            Debug.Assert(command != null, "command is null");
            Debug.Assert(commandTreeFacts != null, "commandTreeFacts is null");
            Debug.Assert(cacheTransactionHandler != null, "cacheTransactionHandler is null");
            Debug.Assert(cachingPolicy != null, "cachingPolicy is null");

            _command = command;
            _commandTreeFacts = commandTreeFacts;
            _cacheTransactionHandler = cacheTransactionHandler;
            _cachingPolicy = cachingPolicy;
        }
Exemplo n.º 11
0
        public CachingConfiguration()
        {
            //TODO : Look for a second level cache that works
            var transactionHandler = new CacheTransactionHandler(new InMemoryCache());

            AddInterceptor(transactionHandler);

            Loaded +=
              (sender, args) => args.ReplaceService<DbProviderServices>(
                (s, _) => new CachingProviderServices(s, transactionHandler,
                  new DefaultCachingPolicy()));
        }
Exemplo n.º 12
0
        public EntityConfiguration()
        {
            if (!Configuration.Cache.Enabled)
                return;

            var transactionHandler = new CacheTransactionHandler(_instance.Value);

            AddInterceptor(transactionHandler);

            Loaded += (sender, args) => args.ReplaceService<DbProviderServices>(
                (s, _) => new CachingProviderServices(s, transactionHandler));
        }
        public void Committed_invalidate_sets_collected_during_transaction()
        {
            var mockCache = new Mock<ICache>();
            var transactionHandler = new CacheTransactionHandler(mockCache.Object);

            var transaction = Mock.Of<DbTransaction>();
            transactionHandler.InvalidateSets(transaction, new[] {"ES1", "ES2"});
            transactionHandler.InvalidateSets(transaction, new[] {"ES3", "ES2"});

            transactionHandler.Committed(transaction, Mock.Of<DbTransactionInterceptionContext>());

            mockCache.Verify(c =>c.InvalidateSets(new[] {"ES1", "ES2", "ES3"}), Times.Once());
        }
        public void Committed_invalidate_sets_collected_during_transaction()
        {
            var mockCache          = new Mock <ICache>();
            var transactionHandler = new CacheTransactionHandler(mockCache.Object);

            var transaction = Mock.Of <DbTransaction>();

            transactionHandler.InvalidateSets(transaction, new[] { "ES1", "ES2" }, null);
            transactionHandler.InvalidateSets(transaction, new[] { "ES3", "ES2" }, null);

            transactionHandler.Committed(transaction, Mock.Of <DbTransactionInterceptionContext>());

            mockCache.Verify(c => c.InvalidateSets(new[] { "ES1", "ES2", "ES3" }, null), Times.Once());
        }
        public void RolledBack_clears_affected_sets_collected_during_transaction()
        {
            var mockCache          = new Mock <ICache>();
            var transactionHandler = new CacheTransactionHandler(mockCache.Object);

            var transaction = Mock.Of <DbTransaction>();

            transactionHandler.InvalidateSets(transaction, new[] { "ES1", "ES2" }, null);
            transactionHandler.InvalidateSets(transaction, new[] { "ES3", "ES2" }, null);

            transactionHandler.RolledBack(transaction, Mock.Of <DbTransactionInterceptionContext>());
            transactionHandler.Committed(transaction, Mock.Of <DbTransactionInterceptionContext>());

            mockCache.Verify(c => c.InvalidateSets(It.IsAny <IEnumerable <string> >(), null), Times.Never());
        }
Exemplo n.º 16
0
        public Configuration()
        {
            SetDatabaseInitializer<WindAuth.Data.DataContext>(new MigrateDatabaseToLatestVersion<WindAuth.Data.DataContext, WindAuth.Migrations.Configuration>());

            var transactionHandler = new CacheTransactionHandler(new InMemoryCache());

            AddInterceptor(transactionHandler);

            var cachingPolicy = new CachingPolicy();

            Loaded +=
              (sender, args) => args.ReplaceService<DbProviderServices>(
                (s, _) => new CachingProviderServices(s, transactionHandler,
                  cachingPolicy));
        }
        public void RolledBack_clears_affected_sets_collected_during_transaction()
        {
            var mockCache = new Mock<ICache>();
            var transactionHandler = new CacheTransactionHandler(mockCache.Object);

            var transaction = Mock.Of<DbTransaction>();
            transactionHandler.InvalidateSets(transaction, new[] { "ES1", "ES2" });
            transactionHandler.InvalidateSets(transaction, new[] { "ES3", "ES2" });

            transactionHandler.RolledBack(transaction, Mock.Of<DbTransactionInterceptionContext>());
            transactionHandler.Committed(transaction, Mock.Of<DbTransactionInterceptionContext>());

            mockCache.Verify(c => c.InvalidateSets(It.IsAny<IEnumerable<string>>()), Times.Never());
        }
Exemplo n.º 18
0
 public CachingProviderServices(DbProviderServices providerServices, CacheTransactionHandler cacheTransactionHandler, CachingPolicy cachingPolicy = null)
 {
     _providerServices        = providerServices;
     _cacheTransactionHandler = cacheTransactionHandler;
     _cachingPolicy           = cachingPolicy ?? new CachingPolicy();
 }
Exemplo n.º 19
0
 public CachingProviderServices(DbProviderServices providerServices, CacheTransactionHandler cacheTransactionHandler, CachingPolicy cachingPolicy = null)
 {
     _providerServices = providerServices;
     _cacheTransactionHandler = cacheTransactionHandler;
     _cachingPolicy = cachingPolicy ?? new CachingPolicy();
 }