Exemplo n.º 1
0
 static void StackExecutions(BitFlyerClient client, ICacheFactory factory, BfProductCode productCode, int count)
 {
     using (var cache = factory.GetExecutionCache(productCode))
     {
         var recs = cache.GetManageTable();
         cache.CommitCount *= 100;
         var completed   = new ManualResetEvent(false);
         var recordCount = 0;
         var sw          = new Stopwatch();
         sw.Start();
         new HistoricalExecutionSource(client, productCode, recs[0].EndExecutionId + count, recs[0].EndExecutionId).Subscribe(exec =>
         {
             cache.Add(exec);
             if ((++recordCount % 10000) == 0)
             {
                 Console.WriteLine("{0} {1} Completed {2} Elapsed", exec.ExecutedTime.ToLocalTime(), recordCount, sw.Elapsed);
             }
         },
                                                                                                                              () =>
         {
             cache.SaveChanges();
             sw.Stop();
             completed.Set();
         });
         completed.WaitOne();
         cache.SaveChanges();
     }
 }
        public IEnumerable <TestCaseData> Caches( )
        {
            ICacheFactory inner = new DictionaryCacheFactory( );

            // Factories to test
            ICacheFactory [] factories = new ICacheFactory []
            {
                new PerTenantCacheFactory {
                    Inner = inner
                },
                new PerTenantNonSharingCacheFactory {
                    Inner = inner
                },
                new DelayedInvalidateCacheFactory {
                    Inner = inner
                },
            };

            // Create test data
            // Note: We return factories instead of caches, because NUnit reuses the same instances if the test is rerun. :p
            foreach (ICacheFactory factory in factories)
            {
                string name = factory.GetType( ).Name.Replace("Factory", "");

                yield return(new TestCaseData(name, factory));
            }
        }
Exemplo n.º 3
0
 public CacheService(
     ILogger <CacheService> logger,
     ICacheFactory cacheFactory)
 {
     _logger       = logger ?? throw new ArgumentNullException(nameof(logger));
     _cacheFactory = cacheFactory ?? throw new ArgumentNullException(nameof(cacheFactory));
 }
Exemplo n.º 4
0
        public HistoricalOhlcSource(ICacheFactory cacheFactory, BfProductCode productCode, TimeSpan frameSpan, DateTime endFrom, TimeSpan span, string cacheFolderBasePath)
        {
            // Create database file if not exists automatically
            _cache = cacheFactory.GetOhlcCache(productCode, frameSpan);
            var requestedCount = Convert.ToInt32(span.TotalMinutes / frameSpan.TotalMinutes);

            endFrom = endFrom.Round(frameSpan);
            var startTo = endFrom - span + frameSpan;
            var end     = endFrom - span + frameSpan;

            _source = Observable.Create <IFxOhlcvv>(observer =>
            {
                var query = _cache.GetOhlcsBackward(endFrom, span);
                if (query.Count() == requestedCount)
                {
                    query.ForEach(ohlc => observer.OnNext(ohlc));
                }
                else
                {
                    // Cryptowatch accepts close-time based range
                    CryptowatchOhlcSource.Get(productCode, frameSpan, endFrom + frameSpan, startTo + frameSpan).OrderByDescending(e => e.Start).ForEach(ohlc =>
                    {
                        _cache.Add(new DbHistoricalOhlc(ohlc, frameSpan));
                        observer.OnNext(ohlc);
                    });
                    _cache.SaveChanges();
                }
                observer.OnCompleted();
                return(() => { });
            });

            // Cryptowatchの取得リミットに到達していた場合の対処
        }
Exemplo n.º 5
0
 static void FillGaps(BitFlyerClient client, ICacheFactory factory, BfProductCode productCode)
 {
     using (var cache = factory.GetExecutionCache(productCode))
     {
         cache.CommitCount *= 100;
         var completed   = new ManualResetEvent(false);
         var recordCount = 0;
         var sw          = new Stopwatch();
         sw.Start();
         cache.FillGaps(client).Subscribe(exec =>
         {
             if ((++recordCount % 10000) == 0)
             {
                 Console.WriteLine("{0} {1} Completed {2} Elapsed", exec.ExecutedTime.ToLocalTime(), recordCount, sw.Elapsed);
             }
         },
                                          () =>
         {
             cache.SaveChanges();
             sw.Stop();
             completed.Set();
         });
         completed.WaitOne();
     }
 }
Exemplo n.º 6
0
        public ApplicationGetByPKStrategyBase(ICacheFactory iCacheFactory, ISetting iSetting)
        {
            _iCacheFactory = iCacheFactory;
            _iSetting      = iSetting;

            Init(iCacheFactory, iSetting);
        }
        public void Test_ItemsRemoved_MultipleRemoves(string cacheName, ICacheFactory factory)
        {
            var cache = factory.Create <int, string>(CacheName);

            List <int> itemsRemoved;

            int [] testKeys;

            testKeys = new [] { 42, 54, 1, 100, 123456 };

            itemsRemoved = new List <int>( );

            cache.ItemsRemoved += (sender, args) => itemsRemoved.AddRange(args.Items);

            foreach (int testKey in testKeys)
            {
                cache.Add(testKey, testKey.ToString( ));
            }

            Assert.That(itemsRemoved, Is.Empty, "Not Empty");

            foreach (int testKey in testKeys)
            {
                cache.Remove(testKey);
                Assert.That(itemsRemoved, Has.Exactly(1).EqualTo(testKey), "Not removed");
            }

            Assert.That(itemsRemoved, Is.EquivalentTo(testKeys));
        }
Exemplo n.º 8
0
 public WhisperService(IWhisperRepository whisperRepoistory, ICacheFactory cacheFactory, IUserRepository userRepository, IHttpClientFactory httpClientFactory)
 {
     _whisperRepoistory = whisperRepoistory;
     _cacheClient       = cacheFactory.CreateClient(CacheType.Redis);
     _userRepository    = userRepository;
     _httpClientFactory = httpClientFactory;
 }
 public RemoteDockerClient(ServiceConfig config, IAuthHandler auth, IDockerDistribution dockerDistribution, ILocalDockerClient localClient, ICacheFactory cacheFactory) :
     base(config, auth)
 {
     this.dockerDistribution = dockerDistribution;
     this.localClient        = localClient;
     this.cacheFactory       = cacheFactory;
 }
Exemplo n.º 10
0
 public CreateMemberSaga(ICacheFactory cacheFactory, ISerializer serializer, IMappingService mappingService,
                         ILogger logger, IMemberService memberService, ICommonBusEndpointSettings commonBusEndpointSettings) : base(
         cacheFactory, serializer, mappingService, logger)
 {
     _memberService             = memberService;
     _commonBusEndpointSettings = commonBusEndpointSettings;
 }
Exemplo n.º 11
0
 public SagaDataCache(ICacheFactory cacheFactory, ISerializer serializer, Guid sagaId)
 {
     Cache        = cacheFactory.NewDisposableCache();
     Serializer   = serializer;
     SagaId       = sagaId;
     CacheHashKey = nameof(SagaDataCache) + sagaId;
 }
Exemplo n.º 12
0
        public ApplicationUpdateStrategyBase(ICacheFactory iCacheFactory, ISetting iSetting)
        {
            _iCacheFactory = iCacheFactory;
            _iSetting      = iSetting;

            Init();
        }
Exemplo n.º 13
0
 public DbContextUnitOfWork(Func <TDbContext> contextFactory, ICacheFactory cacheFactory,
                            IMappingService mappingService, ILogger logger)
 {
     Cache          = cacheFactory.NewDisposableCache();
     DbContext      = contextFactory();
     MappingService = mappingService;
     Store          = new DataStore <TDbContext>(DbContext, MappingService, logger);
 }
Exemplo n.º 14
0
 /**
  * @param IConfig config
  * @param ICacheFactory cacheFactory
  * @param IRequest request
  */
 public URLGenerator(IConfig config,
                     ICacheFactory cacheFactory,
                     IRequest request)
 {
     this.config       = config;
     this.cacheFactory = cacheFactory;
     this.request      = request;
 }
Exemplo n.º 15
0
        public void Test_Clear(string cacheName, ICacheFactory factory)
        {
            var cache = factory.Create <int, string>(CacheName);

            cache.Add(1, "Test");
            cache.Clear( );
            Assert.That(cache.Count, Is.EqualTo(0));
        }
Exemplo n.º 16
0
        public void Test_TryGetOrAdd_NullValueFactory(string cacheName, ICacheFactory factory)
        {
            var cache = factory.Create <int, string>(CacheName);

            string value;

            Assert.Throws <ArgumentNullException>(() => cache.TryGetOrAdd(1, out value, null));
        }
Exemplo n.º 17
0
 public UserUowFactory(ILogger logger, ICacheFactory cacheFactory, IMappingService mappingService,
                       IDbConfig primaryDbConfig, ISerializer serializer, IEventBroadcastingProxy eventDispatchingProxy,
                       IUserProfileConfig userProfileConfig, ICryptoService cryptoService)
     : base(primaryDbConfig, logger, cacheFactory, mappingService, serializer, eventDispatchingProxy)
 {
     _userProfileConfig = userProfileConfig;
     _cryptoService     = cryptoService;
 }
Exemplo n.º 18
0
        public void Test_IEnumerable_Empty(string cacheName, ICacheFactory factory)
        {
            var cache = factory.Create <int, string>(CacheName);

            var values = cache.ToList( );

            Assert.That(values, Has.Count.EqualTo(0));
        }
Exemplo n.º 19
0
 public ClairScanner(ILogger <ClairScanner> logger, ServiceConfig config, IClairAPI clair, ICacheFactory cacheFactory, IWorkQueue <ScanRequest> queue)
 {
     this.logger       = logger;
     this.config       = config;
     this.clair        = clair;
     this.cacheFactory = cacheFactory;
     Queue             = queue;
 }
Exemplo n.º 20
0
 public IndexWorker(ILogger <IndexWorker> logger, ServiceConfig config, IWorkQueue <IndexRequest> queue, IClientFactory clientFactory, IIndexStore indexStore,
                    RegistryAuthenticationDecoder authDecoder, IAuthHandler authHandler, ICacheFactory cacheFactory) : base(logger, config, queue, clientFactory)
 {
     this.indexStore   = indexStore;
     this.authDecoder  = authDecoder;
     this.authHandler  = authHandler;
     this.cacheFactory = cacheFactory;
 }
Exemplo n.º 21
0
 protected Id3TokenStoreBase(ICacheFactory cacheFactory, ISerializer serializer, ILogger logger,
                             IClaimRelatedJsonDeserializer claimRelatedJsonDeserializer)
 {
     CacheFactory = cacheFactory;
     Serializer   = serializer;
     Logger       = logger;
     ClaimRelatedJsonDeserializer = claimRelatedJsonDeserializer;
 }
Exemplo n.º 22
0
 protected SagaBase(ICacheFactory cacheFactory, ISerializer serializer, IMappingService mappingService,
                    ILogger logger)
 {
     CacheFactory   = cacheFactory;
     Serializer     = serializer;
     MappingService = mappingService;
     Logger         = logger;
 }
Exemplo n.º 23
0
 public ClientFactory(ServiceConfig config, ILoggerFactory loggerFactory, IAufsFilter indexer, ILayerExtractor extractor, ICacheFactory cacheFactory)
 {
     this.config        = config;
     this.loggerFactory = loggerFactory;
     logger             = loggerFactory.CreateLogger <ClientFactory>();
     this.indexer       = indexer;
     this.extractor     = extractor;
     this.cacheFactory  = cacheFactory;
 }
Exemplo n.º 24
0
        public ICacheFactory CacheFactory()
        {
            if (_cacheFactory == null)
            {
                _cacheFactory = new CacheFactory();
            }

            return(_cacheFactory);
        }
Exemplo n.º 25
0
        public void Test_GetIndexer_Miss(string cacheName, ICacheFactory factory)
        {
            var cache = factory.Create <int, string>(CacheName);

            string value = cache [1];

            // Should this throw?
            Assert.That(value, Is.EqualTo(null));
        }
Exemplo n.º 26
0
        public void Test_Get_Hit(string cacheName, ICacheFactory factory)
        {
            var cache = factory.Create <int, string>(CacheName);

            cache.Add(1, "Test");
            string value = cache.Get(1);

            Assert.That(value, Is.EqualTo("Test"));
        }
Exemplo n.º 27
0
        public void Test_SetIndexer_Get(string cacheName, ICacheFactory factory)
        {
            var cache = factory.Create <int, string>(CacheName);

            cache [1] = "Test";
            string value = cache.Get(1);

            Assert.That(value, Is.EqualTo("Test"));
        }
Exemplo n.º 28
0
        public void Test_Add_Null(string cacheName, ICacheFactory factory)
        {
            var cache = factory.Create <int, string>(CacheName);

            cache.Add(1, null);
            string value = cache.Get(1);

            Assert.That(value, Is.Null);
        }
Exemplo n.º 29
0
        public void Test_Remove_NonExisting(string cacheName, ICacheFactory factory)
        {
            var cache = factory.Create <int, string>(CacheName);

            cache.Add(1, "Test");
            cache.Remove(2);
            Assert.That(cache.ContainsKey(1), Is.True);
            Assert.That(cache.Count, Is.EqualTo(1));
        }
Exemplo n.º 30
0
        /// <summary>
        /// Create a cache, using the specified type parameters.
        /// </summary>
        /// <param name="cacheName">The cache name.</param>
        public ICache <TKey, TValue> Create <TKey, TValue>(string cacheName)
        {
            if (Private == null)
            {
                Private = new DictionaryCacheFactory();
            }
            var innerCache = Inner.Create <TKey, TValue>(cacheName);

            return(new TransactionAwareCache <TKey, TValue>(cacheName, innerCache, Private.Create <TKey, TValue>));
        }
Exemplo n.º 31
0
        public PreprocessedDataCache(ICacheFactory factory)
        {
            if (factory == null)
                throw new ArgumentNullException("PreprocessedDataCache.ctor(): factory cannot be null!");
            this.factory = factory;

            distanceTimeCache = new Dictionary<Pair<Coordinate, Coordinate>, Pair<int, int>>();
            distanceTimeDelta = new Dictionary<Pair<Coordinate, Coordinate>, Pair<int, int>>();

            nearestLocationCache = new Dictionary<Coordinate, Coordinate>();
            nearestLocationDelta = new Dictionary<Coordinate, Coordinate>();
        }
Exemplo n.º 32
0
 public static void SetCurrent(ICacheFactory factory)
 {
     _cacheFactory = factory;
 }
Exemplo n.º 33
0
 /// <summary>
 /// Sets the Default CacheFactory Instance
 /// </summary>
 /// <param name="cacheFactory">ICacheFactory Instance</param>
 public static void SetDefaultCacheFactory(ICacheFactory cacheFactory)
 {
     if(Equals(cacheFactory, null))
         throw new ArgumentNullException("cacheFactory");
     _defaultCacheFactory = cacheFactory;
 }
Exemplo n.º 34
0
		public void SetUp()
		{
			factory = GetCacheFactory();
			cache = factory.CreateCache();
		}