public void Init() { _cache = new MemoryCacheService { ExpirationTimeSpan = TimeSpan.FromSeconds(1) }; _cache.Clear(); }
public PageByFieldTemplateCache( FieldTemplateService fieldTemplateService, DataService dataService, EventBroker eventBroker, MemoryCacheService memoryCacheService, AuthorizationService authorizationService, PageService pageService, IServiceProvider serviceProvider, RouteRequestLookupInfoAccessor routeRequestLookupInfoAccessor) { var fieldType = ActivatorUtilities.CreateInstance <T>(serviceProvider); _fieldTemplateService = fieldTemplateService; _dataService = dataService; _memoryCacheService = memoryCacheService; _authorizationService = authorizationService; _pageService = pageService; _fieldTemplateName = fieldType.Name; _cacheKey = GetType().FullName + ":" + _fieldTemplateName; eventBroker.Subscribe <FieldTemplateCreated>(_ => _memoryCacheService.Remove(_cacheKey)); eventBroker.Subscribe <FieldTemplateDeleted>(_ => _memoryCacheService.Remove(_cacheKey)); eventBroker.Subscribe <DraftPageCreated>(_ => _memoryCacheService.Remove(_cacheKey)); eventBroker.Subscribe <PageCreated>(_ => _memoryCacheService.Remove(_cacheKey)); eventBroker.Subscribe <PageDeleted>(_ => _memoryCacheService.Remove(_cacheKey)); eventBroker.Subscribe <PageUpdated>(x => { if (x.OriginalFieldTemplateSystemId != null) { _memoryCacheService.Remove(_cacheKey); } }); _routeRequestLookupInfoAccessor = routeRequestLookupInfoAccessor; }
public static void Register(HttpConfiguration config) { // Web API configuration and services // Web API routes config.MapHttpAttributeRoutes(); var cacheService = new MemoryCacheService(int.Parse(ConfigurationManager.AppSettings["CacheDurationInSeconds"])); var configuration = new CachedConfiguration(new ConfigurationManagerConfiguration(), cacheService); var webProxyUserRepository = new CachedWebProxyUserRepository(new SqlServerWebProxyUserRepository(configuration), cacheService); //var proxyLogging = new FileProxyLogging(configuration); var proxyLogging = new AzureBlobStorageLogging(configuration); //var proxyLogging = new NullProxyLogging(); //var proxyRouting = new LogicRouting(); var proxyRouting = new NasAvWebServicesRouting(configuration, webProxyUserRepository); config.Routes.MapHttpRoute(name: "Proxy", routeTemplate: "{*path}", handler: HttpClientFactory.CreatePipeline( innerHandler: new HttpClientHandler(), // will never get here if proxy is doing its job handlers: new DelegatingHandler[] { new ProxyHandler(proxyRouting, proxyLogging, configuration) }), defaults: new { path = RouteParameter.Optional }, constraints: null ); }
public async Task MemoryCacheService_GetAsync_CachedObjectWithSeveralCalls_Succeeds() { //Arrange MemoryCacheService service = GetMemoryCacheService(); string key = "testKey"; int getInvokedCount = 0; Task <int> myFunc() { getInvokedCount++; return(Task.FromResult(10)); } //Action Task <int> resultTask1 = service.GetAsync(key, myFunc); Task <int> resultTask2 = service.GetAsync(key, myFunc); Task <int> resultTask3 = service.GetAsync(key, myFunc); Task <int> resultTask4 = service.GetAsync(key, myFunc); Task <int> resultTask5 = service.GetAsync(key, myFunc); int result1 = await resultTask1; int result2 = await resultTask2; int result3 = await resultTask3; int result4 = await resultTask4; int result5 = await resultTask5; //Asserts Assert.AreEqual(10, result1); Assert.AreEqual(10, result2); Assert.AreEqual(10, result3); Assert.AreEqual(10, result4); Assert.AreEqual(10, result5); Assert.AreEqual(1, getInvokedCount); }
public void MemoryCacheTest() { Configuration.Setup(new MemoryCacheSettings { JsonSettings = new JsonSerializerSettings { Formatting = Formatting.Indented }, ParallelGet = false }, true); Configuration.Container.Register(typeof(UnitTest1).GetMethod(nameof(UnitTest1.Get)), this); //Use dependency injection if possible MemoryCacheService service = new MemoryCacheService(); int param1 = 3; string param2 = "testing"; bool param3 = false; var vm = service.Get <TestVm>(new System.Collections.Generic.Dictionary <string, object> { { nameof(param1), param1 }, { nameof(param2), param2 }, { nameof(param3), param3 }, }); service.Clean(); Assert.NotNull(vm); }
public override void RegisterServices() { base.RegisterServices(); var serviceCollection = new ServiceCollection(); // All services are singletons in a desktop application var configurationService = new ConfigurationService(); var commandService = new CommandService(); var memoryCacheService = new MemoryCacheService(); var navigationService = new NavigationService(commandService); var sharedService = new SharedService(commandService, configurationService); ConfigureServices(serviceCollection, configurationService, commandService, memoryCacheService, navigationService, sharedService); // Adds the plugin system serviceCollection.AddPrise <IJayaPlugin>(options => options .WithPluginAssemblyName("Jaya.Provider.FileSystem.dll") .WithRootPath(GetRootPath()) .ConfigureSharedServices(services => { ConfigureServices(services, configurationService, commandService, memoryCacheService, navigationService, sharedService); }) ); // Adds all the registered services to the ServiceLocator ServiceLocator.Create(serviceCollection.BuildServiceProvider()); // Now, we have access to all services like before ServiceLocator.Instance.GetService <ISharedService>().LoadConfigurations(); }
public static IUnityContainer BuildContainer() { var currentContainer = new UnityContainer(); var memoryCache = new MemoryCacheService(new MemoryCacheOptions()); currentContainer.RegisterInstance <IMemoryCache>(memoryCache); var config = AutoMapperConfig.RegisterMappings(); IMapper mapper = config.CreateMapper(); currentContainer.RegisterInstance <IMapper>(mapper); //var appDbContext = new AppDbContext(); //var eFUnitOfWork = new EFUnitOfWork(appDbContext); //currentContainer.RegisterInstance<IUnitOfWork>(eFUnitOfWork); currentContainer.RegisterType <ITestTableRepository, TestTableRepository>(); currentContainer.RegisterType <ITestTableService, TestTableService>(); currentContainer.RegisterType <IYayoiCryptor, AESUtils>(); // note: registering types could be moved off to app config if you want as well return(currentContainer); }
public void Init() { _memoryCacheService = new MemoryCacheService { ExpirationTimeSpan = TimeSpan.FromSeconds(1) }; _memoryCacheService.Clear(); _repositoryMock = new RepositoryMock(); _cachedRepository = new CachedRepository(_repositoryMock, _memoryCacheService); }
public void Setup() { _memoryCacheService = new MemoryCacheService(new Mock <ILogService>().Object); _cacheKeyEntry = new TestCacheKeyEntry(); _testCachedObject = new TestCachedObject { DateTimeCached = DateTime.Now }; _testFunc = (i => _testCachedObject); }
public NotUseAnything() { var memoryCache = new MemoryCacheService(new MemoryCacheOptions()); _yayoiCryptor = new DES(memoryCache); InitializeComponent(); }
private void AddConnectionsId(IList <string> connectionsIdList, IList <string> usersId, int applicationId) { var connectionsId = MemoryCacheService.GetConnectionId(usersId, applicationId); foreach (var connectionId in connectionsId) { connectionsIdList.Add(connectionId); } }
public void MustBeAbleToPullAMissingValueWithoutError() { var key = string.Empty; var service = new MemoryCacheService(); var result = service.Get <TestDomainObjA>(key); Assert.IsNull(result); }
public void GetGithubUser_NotInCache_ReturnNull() { var memoryCacheFake = new PassiveMemoryCacheFake(); var cacheService = new MemoryCacheService(memoryCacheFake); var githubUser = cacheService.GetGithubUser("notInCacheUser"); Assert.Null(githubUser); }
public void GetGithubUser_InCache_ReturnGithubUser() { var memoryCacheFake = new PassiveMemoryCacheFake(); var cacheService = new MemoryCacheService(memoryCacheFake); var githubUser = cacheService.GetGithubUser("fromCache01"); Assert.NotNull(githubUser); }
public DbInitializer(IBusiness <AlbumEntity, AlbumDto> repository, IRepository <CashbackEntity> repositoryCashback, MemoryCacheService cache, ClientRest client, IMapper mapper) { Repository = repository; RepositoryCashback = repositoryCashback; Cache = cache; Client = client; Mapper = mapper; }
public UsingInterfaceClassForm() { var memoryCache = new MemoryCacheService(new MemoryCacheOptions()); //_yayoiCryptor = new AESUtils(memoryCache); _yayoiCryptor = new DES(memoryCache); InitializeComponent(); }
public void Clear_Should_Remove_All_Values() { var service = new MemoryCacheService(); var key = "key"; var value = "Hello, World!"; service.Set(key, value); Assert.NotNull(service.Get(key)); service.Clear(); Assert.Null(service.Get(key)); }
public void ShouldNotBeAbleToPullTheSameValueAfterTheCacheHasExpired() { var key = GenerateUniqueKey(); var service = new MemoryCacheService(1); service.Set(key, int.MaxValue); Thread.Sleep(1); var result = service.Get <int>(key); Assert.AreEqual(default(int), result); }
public void ShouldBeAbleToHandleATypeMismatch() { var key = GenerateUniqueKey(); var service = new MemoryCacheService(); var testValue = new Guid(); var testObj = new TestDomainObjA(testValue); service.Set(key, testObj); var result = service.Get <TestDomainObjB>(key); Assert.IsNull(result); }
public void ShouldBeAbleToHandleAPrimitiveType() { var key = GenerateUniqueKey(); var service = new MemoryCacheService(); const int testValue = int.MaxValue; service.Set(key, testValue); var result = service.Get <int>(key); Assert.IsNotNull(result); Assert.AreEqual(result, testValue); Assert.IsInstanceOfType(result, typeof(int)); }
public void MemoryCacheService_ShouldReturnDataFromCache() { ICacheService service = new MemoryCacheService(cache, serviceConfig); List <IData> data = new List <IData>() { new Data { Gender = "Male" } }; service.CacheServiceData(data); var cachedValue = service.GetServiceData(); Assert.NotNull(cachedValue); Assert.Single(cachedValue); }
public void ShouldBeAbleToUseARetreivalFunction() { var key = GenerateUniqueKey(); var passedValue = new Guid(); var service = new MemoryCacheService(); var testService = new TestExampleServiceImplementation(); var firstResult = service.Get(key, () => testService.ReturnGuidThatWasPassedIn(passedValue)); var secondResult = service.Get <Guid>(key); Assert.AreEqual(passedValue, firstResult); Assert.AreEqual(firstResult, secondResult); }
public void MustBeAbleToPullSomethingPutIntoIt() { var key = GenerateUniqueKey(); var service = new MemoryCacheService(); var testValue = new Guid(); var testObj = new TestDomainObjA(testValue); service.Set(key, testObj); var result = service.Get <TestDomainObjA>(key); Assert.IsNotNull(result); Assert.AreEqual(result.TestValue, testValue); }
public void MemoryCacheService_ShouldReturnDataFromCache() { ICacheService service = new MemoryCacheService(cache, serviceConfig); List <IData> data = new List <IData>() { new Data { BrandName = "Sample", Color = "Black", OwnerName = "David Jonh" } }; service.CacheServiceData(data); var cachedValue = service.GetServiceData(); Assert.NotNull(cachedValue); Assert.Single(cachedValue); Assert.Equal(data, cachedValue); }
public void MemoryCacheService_ShouldWriteCache() { ICacheService service = new MemoryCacheService(cache, serviceConfig); List <IData> data = new List <IData>() { new Data { Gender = "Male" } }; var cachedValue = cache.Get <List <IData> >(MemoryCacheService.DATA_CACHE_NAME); Assert.Null(cachedValue); service.CacheServiceData(data); cachedValue = cache.Get <List <IData> >(MemoryCacheService.DATA_CACHE_NAME); Assert.NotNull(cachedValue); }
public void ShouldBeAbleToHandleATypesInAHeirarchy() { var key = GenerateUniqueKey(); var service = new MemoryCacheService(); var testValue = new Guid(); var testObj = new TestDomainObjectC(testValue); service.Set(key, testObj); var result = service.Get <TestDomainObjA>(key); Assert.IsNotNull(result); Assert.AreEqual(result.TestValue, testValue); Assert.IsInstanceOfType(result, typeof(TestDomainObjectC)); }
public void MemoryCacheService_ShouldWriteCache() { ICacheService service = new MemoryCacheService(cache, serviceConfig); List <IData> data = new List <IData>() { new Data { BrandName = "Sample", Color = "Black", OwnerName = "David Jonh" } }; var cachedValue = cache.Get <List <IData> >(MemoryCacheService.DATA_CACHE_NAME); Assert.Null(cachedValue); service.CacheServiceData(data); cachedValue = cache.Get <List <IData> >(MemoryCacheService.DATA_CACHE_NAME); Assert.NotNull(cachedValue); }
static RedisServer() { var config = new ConfigHelper(); Config = config.Reader <RedisConfig>("config/Redis.json"); MemoryCache = new MemoryCacheService(null); //var redisConfig = WebConfig.AppSettingsName<string>("RedisConfig", "config/redis.cfg"); //if (Config != null) return; ////var file=IoFiles.GetFileMapPath("config/redis.cfg") //Config = CfgConfig.Reader<RedisConfig>(redisConfig, "redis"); if (string.IsNullOrEmpty(Config?.Connect)) { Config = new RedisConfig { IsCache = false }; } else { if (Config.DefaultDatabase > 0) { Config.Connect = Config.Connect + ",defaultDatabase=" + Config.DefaultDatabase; } } if (!Config.IsCache) { IsCacheError = true; } try { var connect = ConnectionMultiplexer.Connect(Config.Connect); var res = connect.ClientName; } catch (Exception exception) { Config.IsCache = false; LogHelper.Log(exception); IsCacheError = true; } //finally //{ // Config.IsCache = false; // IsCacheError = true; //} }
public void MemoryCacheService_ShouldReturnNull_AfterTimeout() { ICacheService service = new MemoryCacheService(cache, serviceConfig); List <IData> data = new List <IData>() { new Data { BrandName = "Sample", Color = "Black", OwnerName = "David Jonh" } }; service.CacheServiceData(data); var cachedValue = service.GetServiceData(); Assert.NotNull(cachedValue); Thread.Sleep(serviceConfig.Value.DataCacheTimeout * 1000 + 1); cachedValue = service.GetServiceData(); Assert.Null(cachedValue); }
public void MemoryCacheService_ShouldReturnNull_AfterTimeout() { ICacheService service = new MemoryCacheService(cache, serviceConfig); List <IData> data = new List <IData>() { new Data { Gender = "Male" } }; service.CacheServiceData(data); var cachedValue = service.GetServiceData(); Assert.NotNull(cachedValue); Thread.Sleep(serviceConfig.Value.DataCacheTimeout * 1000 + 1); cachedValue = service.GetServiceData(); Assert.Null(cachedValue); }