Exemplo n.º 1
0
 public static TResult GetCachedData <T, TResult>(ICacheSettings settings, Func <T, TResult> method, T arg1, params Object[] args)
 {
     return(CacheUtils.GetCachedData_Proxy(
                settings,
                method.Method.DeclaringType.GetFriendlyTypeName(),
                method.Method.Name,
                ((Object[] argv) => (method.Invoke(arg1))),
                arg1, args));
 }
 public ApprenticeshipOrchestrator(IMediator mediator, ILog logger, IFrameworkDetailsViewModelMapper frameworkDetailsViewModelMapper, IStandardDetailsViewModelMapper standardDetailsViewModelMapper, ICacheStorageService cacheStorageService, ICacheSettings cacheSettings)
 {
     _mediator = mediator;
     _logger   = logger;
     _frameworkDetailsViewModelMapper = frameworkDetailsViewModelMapper;
     _standardDetailsViewModelMapper  = standardDetailsViewModelMapper;
     _cacheService  = cacheStorageService;
     _cacheSettings = cacheSettings;
 }
Exemplo n.º 3
0
 public ParticipationsSessionRepository(
     IParticipationRepository participationRepository, ICache cache, ICacheSettings settings,
     IReadTestRepository readTestRepository)
 {
     _participationRepository = participationRepository;
     _cache              = cache;
     _settings           = settings;
     _readTestRepository = readTestRepository;
 }
Exemplo n.º 4
0
 public MockTypedBuilderSettings(
     IMockFormatter formatter,
     ICacheSettings cacheSettings,
     IEnumerable<ITypedHandler> handlers,
     IEnumerable<ITypedResponseValidator> responseValidators) 
         : base(formatter, cacheSettings, handlers, responseValidators)
 {
     _formatter = formatter;
 }
 public TResult UpdateCachedData <T1, T2, TResult>(ICacheSettings settings, Func <T1, T2, TResult> method, TResult data, T1 arg1, T2 arg2, params Object[] args)
 {
     return(this.UpdateCachedData_Proxy(
                settings,
                method.Method.DeclaringType.GetFriendlyTypeName(),
                method.Method.Name,
                ((Object[] argv) => (method.Invoke(arg1, arg2))),
                data,
                arg1, arg2, args));
 }
 public TResult UpdateCachedData <T1, T2, T3, T4, T5, T6, T7, T8, TResult>(ICacheSettings settings, Func <T1, T2, T3, T4, T5, T6, T7, T8, TResult> method, TResult data, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, params Object[] args)
 {
     return(this.UpdateCachedData_Proxy(
                settings,
                method.Method.DeclaringType.GetFriendlyTypeName(),
                method.Method.Name,
                ((Object[] argv) => (method.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))),
                data,
                arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, args));
 }
 public HttpCacheConfigurationHandler(ICacheSettings settings, ICacheManager cacheManager, IEnumerable <IHttpCacheHandler> handlers)
     : base(settings, cacheManager)
 {
     if (handlers != null)
     {
         foreach (var handler in handlers)
         {
             Settings.HandlerRegister.WithHandler(handler);
         }
     }
 }
Exemplo n.º 8
0
 public BaseOperationManager(string transactionId = null)
 {
     DataOperation = SetDataOperation();
     TransactionId = transactionId;
     Mapper        = SetMapper();
     CacheSettings = SetCacheSettings();
     if (IsCacheActive())
     {
         CacheManager = CacheSettings.CacheManager;
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CacheSection{TValue}"/> class.
        /// </summary>
        /// <param name="sectionName">Section name.</param>
        /// <param name="memoryCache">Provided memory cache.</param>
        /// <param name="configureCacheEntry">External configure function.</param>
        /// <param name="settings">Cache settings.</param>
        public CacheSection(
            [NotNull] string sectionName,
            [NotNull] IMemoryCache memoryCache,
            Action <ICacheEntryContext>?configureCacheEntry = null,
            ICacheSettings <TValue>?settings = null)
        {
            sectionName.AssertArgumentNotNull(nameof(sectionName));

            _cacheSectionDescriptor = new CacheSectionDescriptor <TValue>(sectionName, settings ?? CacheSettings <TValue> .Default);
            _memoryCache            = memoryCache.AssertArgumentNotNull(nameof(memoryCache));
            _configureCacheEntry    = configureCacheEntry;
        }
 public BasketOrchestrator(IMediator mediator,
                           ICookieManager cookieManager,
                           IBasketViewModelMapper basketViewModelMapper,
                           ICacheStorageService cacheService,
                           ICacheSettings cacheSettings,
                           IFatConfigurationSettings config)
 {
     _mediator              = mediator;
     _cookieManager         = cookieManager;
     _basketViewModelMapper = basketViewModelMapper;
     _cacheService          = cacheService;
     _cacheSettings         = cacheSettings;
     _config = config;
 }
        public HttpBuilderSettings(ICacheSettings cacheSettings, IEnumerable <IHttpHandler> handlers, IEnumerable <IHttpResponseValidator> responseValidators)
            : this()
        {
            CacheSettings     = cacheSettings;
            ResponseValidator = new ResponseValidatorCollection(responseValidators);

            if (handlers != null)
            {
                foreach (var handler in handlers)
                {
                    HandlerRegister.WithHandler(handler);
                }
            }
        }
Exemplo n.º 12
0
        // Overload
        /// <exclude />
        public static CachingSettings GetNamedCaching(string name)
        {
            ICacheSettings cacheSettings = Caching.Caches.FirstOrDefault(f => f.Name == name);

            bool enabled = Caching.Enabled;
            int  size    = CachingSettings.DefaultCacheSize;

            if ((enabled) && (cacheSettings != null))
            {
                enabled = cacheSettings.Enabled && cacheSettings.Size != CachingSettings.NoCacheSize;
                size    = cacheSettings.Size;
            }

            CachingSettings cachingSettings = new CachingSettings(enabled, size);

            return(cachingSettings);
        }
Exemplo n.º 13
0
        public TypedBuilderSettings(
            IFormatter formatter,
            ICacheSettings cacheSettings,
            IEnumerable <ITypedHandler> handlers,
            IEnumerable <ITypedResponseValidator> responseValidators)
            : this()
        {
            Formatter         = formatter;
            ResponseValidator = new ResponseValidatorCollection(responseValidators);
            CacheSettings     = cacheSettings;

            if (handlers != null)
            {
                foreach (var handler in handlers)
                {
                    HandlerRegister.WithHandler(handler);
                }
            }
        }
Exemplo n.º 14
0
 public TrainingProviderOrchestrator(
     IMediator mediator,
     ISearchResultsViewModelMapper searchResultsViewModelMapper,
     ILog logger,
     ITrainingProviderDetailsViewModelMapper trainingProviderDetailsViewModelMapper,
     ITrainingProviderSearchFilterViewModelMapper trainingProviderSearchFilterViewModelMapper,
     ICacheStorageService cacheService,
     ICacheSettings cacheSettings,
     ITrainingProviderClosestLocationsViewModelMapper trainingProviderClosestLocationsViewModelMapper)
 {
     _mediator = mediator;
     _searchResultsViewModelMapper = searchResultsViewModelMapper;
     _logger = logger;
     _trainingProviderDetailsViewModelMapper      = trainingProviderDetailsViewModelMapper;
     _trainingProviderSearchFilterViewModelMapper = trainingProviderSearchFilterViewModelMapper;
     _cacheService  = cacheService;
     _cacheSettings = cacheSettings;
     _trainingProviderClosestLocationsViewModelMapper = trainingProviderClosestLocationsViewModelMapper;
 }
Exemplo n.º 15
0
        // NOTE: This section looks horrible - it is, but it's how .Net natively supports Function and Action classes - up to 16 generic parameters.
        //       Maybe one day we won't need these.

        private static TResult GetCachedData_Proxy <TResult>(ICacheSettings settings, String methodType, String methodName, MethodDelegate <TResult> @delegate, params Object[] args)
        {
            // Default cache settings
            settings = settings ?? CacheUtils.UnderlyingProvider.DefaultSettings;

            #region Build CacheKey

            String cacheKey = settings.CacheKeyOverride;

            if (String.IsNullOrWhiteSpace(cacheKey))
            {
                cacheKey = CacheUtils.UnderlyingProvider.BuildCacheKey(String.Format("{0}.{1}", methodType, methodName), args);
            }

            #endregion

            settings.CacheKeyOverride = cacheKey;

            return(CacheUtils.UnderlyingProvider.GetCachedData <TResult>(settings, @delegate, args));
        }
Exemplo n.º 16
0
        public HaloSession(IProduct product, IHaloSharpTimer timer, ICacheSettings cacheSettings = null, IObjectCache cache = null)
        {
            Cache.MetadataCacheDuration = cacheSettings?.MetadataCacheDuration;
            Cache.ProfileCacheDuration  = cacheSettings?.ProfileCacheDuration;
            Cache.StatsCacheDuration    = cacheSettings?.StatsCacheDuration;
            Cache.ObjectCache           = cache;

            if (product.RateLimit != null)
            {
                _rateGate = new RateGate(product.RateLimit, timer);
            }

            var handler = new HttpClientHandler
            {
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
            };

            _httpClient = new HttpClient(handler);
            _httpClient.DefaultRequestHeaders.Add(HeaderName, product.SubscriptionKey);
        }
Exemplo n.º 17
0
        public async Task <string> ReadText(string fileName)
        {
            var result = string.Empty;

            _cacheSettings = _cacheSettingsFactory.GetCacheSettings(CacheTypes.FileSystem, fileName);
            if (_cacheSettings.IsEnabled)
            {
                result = await _cacheManager.Get <string>(_cacheSettings.KeyPrefix);
            }

            if (result == null)
            {
                result = await _fileService.ReadText(fileName);

                if (_cacheSettings.IsEnabled)
                {
                    await _cacheManager.Set(_cacheSettings.KeyPrefix, result.ToString());
                }
            }

            return(result);
        }
        public void DeleteCachedData <TResult>(ICacheSettings settings, MethodDelegate <TResult> @delegate, params Object[] args)
        {
            // TODO: Support Locking Here

            // Default cache settings
            if (settings == null)
            {
                settings = this.DefaultSettings;
            }

            #region Build CacheKey

            String cacheKey = settings.CacheKeyOverride;

            if (String.IsNullOrWhiteSpace(cacheKey))
            {
                cacheKey = this.BuildCacheKey(@delegate, args);
            }

            #endregion

            this._cache.Remove(cacheKey);
        }
        // NOTE: This section looks horrible - it is, but it's how .Net natively supports Function and Action classes - up to 16 generic parameters.
        //       Maybe one day we won't need these.

        private void DeleteCachedData_Proxy <TResult>(ICacheSettings settings, String methodType, String methodName, MethodDelegate <TResult> @delegate, params Object[] args)
        {
            // Default cache settings
            if (settings == null)
            {
                settings = this.DefaultSettings;
            }

            #region Build CacheKey

            String cacheKey = settings.CacheKeyOverride;

            if (String.IsNullOrWhiteSpace(cacheKey))
            {
                cacheKey = this.BuildCacheKey(String.Format("{0}.{1}", methodType, methodName), args);
            }

            #endregion

            settings.CacheKeyOverride = cacheKey;

            this.DeleteCachedData <TResult>(settings, @delegate, args);
        }
Exemplo n.º 20
0
 public static TResult GetCachedData <TResult>(this ICacheProvider cacheProvider, ICacheSettings settings, Func <TResult> method, params Object[] args)
 {
     return(cacheProvider.GetCachedData_Proxy(
                settings,
                method.Method.DeclaringType.GetFriendlyTypeName(),
                method.Method.Name,
                ((Object[] argv) => (method.Invoke())),
                args));
 }
Exemplo n.º 21
0
 public void UpdateCacheSettingsParameter(ICacheSettings cacheType)
 {
     cacheType.Environment.ConfigSet.LastUpdate = DateTime.UtcNow;
     Repository.SaveChanges();
 }
        public TResult GetCachedData <TResult>(ICacheSettings settings, MethodDelegate <TResult> @delegate, params Object[] args)
        {
            // Default cache settings
            if (settings == null)
            {
                settings = this.DefaultSettings;
            }

            #region Build CacheKey

            String  cacheKey = settings.CacheKeyOverride;
            Boolean inLock   = false;

            if (String.IsNullOrWhiteSpace(cacheKey))
            {
                cacheKey = this.BuildCacheKey(@delegate, args);
            }

            #endregion

            // Add tracking key immediately
            // No point only adding it on success, because if there's an error, we don't want to cache the error state, so the dependency SHOULD fail
            this.AddTracking(cacheKey);

            #region Non Locking Cache Retrieval

            // Load data from cache
            Object buffer = this._cache.Get(cacheKey);

#if CACHENULLS
            if (buffer == TrackingCacheProvider.NULL_OBJECT)
            {
                return(default(TResult));
            }
#endif

            if (buffer is TResult)
            {
                return((TResult)buffer);
            }

            #endregion

            #region Locking Cache Retrieval

            if (buffer == null && ConfigurationManager.AppSettings["Dolkens.Framework.Caching.Lock"].ToBoolean(true))
            {
                if (this._lockTable[cacheKey] == null)
                {
                    // Only process a single thread for a particular cacheKey at a time
                    lock (this._lockTable)
                    {
                        if (this._lockTable[cacheKey] == null)
                        {
                            this._lockTable[cacheKey] = this._lockTable[cacheKey] ?? new Object();
                        }
                    }
                }

                inLock = Monitor.TryEnter(this._lockTable[cacheKey], settings.LockTimeout);

                buffer = this._cache.Get(cacheKey);

                if (buffer == TrackingCacheProvider.NULL_OBJECT)
                {
                    if (inLock)
                    {
                        Monitor.Exit(this._lockTable[cacheKey]);
                    }

                    return(default(TResult));
                }

                if (buffer is TResult)
                {
                    if (inLock)
                    {
                        Monitor.Exit(this._lockTable[cacheKey]);
                    }

                    return((TResult)buffer);
                }
            }

            #endregion

            #region Retrieve Fresh Data

            if (buffer == null)
            {
                // Swap in a clean tracking list
                IEnumerable <String> trackingList = this.SwapTracking(null);

                try
                {
                    buffer = @delegate(args);
                }
                catch (Exception ex)
                {
                    // Release the lock
                    if (inLock)
                    {
                        Monitor.Exit(this._lockTable[cacheKey]);
                    }

                    // Bubble exception
                    throw ex;
                }
                finally
                {
                    // Return tracking list to normal
                    trackingList = this.SwapTracking(trackingList);
                }

                #region Cache Storage

#if !CACHENULLS
                // Early exit for empty result
                // TODO: Consider adding option to cache NULL data here
                if (buffer == null)
                {
                    return(buffer = null);
                }
#endif

                #region Ensure we have a dependency and that we have a cachekey collection to add to

                settings.Dependencies           = settings.Dependencies ?? this.DefaultDependency;
                settings.Dependencies.CacheKeys = settings.Dependencies.CacheKeys ?? new String[] { };

                #endregion

                settings.Dependencies.CacheKeys = settings.Dependencies.CacheKeys.Union(trackingList).Distinct().ToArray();

                CacheItem cacheItem = null;

#if CACHENULLS
                if (buffer == null)
                {
                    cacheItem = new CacheItem(cacheKey, TrackingCacheProvider.NULL_OBJECT, "CacheUtils");
                }
                else
#endif
                cacheItem = new CacheItem(cacheKey, buffer, "CacheUtils");

                // Save Data To Cache
                this._cache.Add(cacheItem, settings.GetCacheItemPolicy());

                #endregion
            }

            #endregion

            // Release the lock
            if (inLock)
            {
                Monitor.Exit(this._lockTable[cacheKey]);
            }

            return((TResult)buffer);
        }
Exemplo n.º 23
0
 public InMemoryCacheRepository(ICacheSettings cacheSettings)
     : base(cacheSettings)
 {
 }
        protected virtual ITypedBuilderSettings GetSettings(IFormatter formatter, IList <ITypedHandler> handlers, ICacheSettings cacheSettings, IEnumerable <ITypedResponseValidator> validators)
        {
            var settings = new TypedBuilderSettings(formatter, cacheSettings, handlers, validators);

            return(settings);
        }
 protected virtual IList <ITypedHandler> GetHandlers(ICacheSettings cacheSettings, IEnumerable <ITypedCacheHandler> handlers)
 {
     return(new ITypedHandler[] { new TypedCacheConfigurationHandler(cacheSettings, Cache.Current, handlers) });
 }
Exemplo n.º 26
0
 public static TResult GetCachedData <T1, T2, T3, T4, T5, T6, TResult>(this ICacheProvider cacheProvider, ICacheSettings settings, Func <T1, T2, T3, T4, T5, T6, TResult> method, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, params Object[] args)
 {
     return(cacheProvider.GetCachedData_Proxy(
                settings,
                method.Method.DeclaringType.GetFriendlyTypeName(),
                method.Method.Name,
                ((Object[] argv) => (method.Invoke(arg1, arg2, arg3, arg4, arg5, arg6))),
                arg1, arg2, arg3, arg4, arg5, arg6, args));
 }
Exemplo n.º 27
0
 public static void DeleteCachedData <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>(this ICacheProvider cacheProvider, ICacheSettings settings, Func <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> method, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, params Object[] args)
 {
     cacheProvider.DeleteCachedData_Proxy(
         settings,
         method.Method.DeclaringType.GetFriendlyTypeName(),
         method.Method.Name,
         ((Object[] argv) => (method.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10))),
         arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, args);
 }
Exemplo n.º 28
0
 public static void DeleteCachedData <T1, T2, T3, TResult>(this ICacheProvider cacheProvider, ICacheSettings settings, Func <T1, T2, T3, TResult> method, T1 arg1, T2 arg2, T3 arg3, params Object[] args)
 {
     cacheProvider.DeleteCachedData_Proxy(
         settings,
         method.Method.DeclaringType.GetFriendlyTypeName(),
         method.Method.Name,
         ((Object[] argv) => (method.Invoke(arg1, arg2, arg3))),
         arg1, arg2, arg3, args);
 }
Exemplo n.º 29
0
        // NOTE: This section looks horrible - it is, but it's how .Net natively supports Function and Action classes - up to 16 generic parameters.
        //       Maybe one day we won't need these.

        private static void DeleteCachedData_Proxy <TResult>(this ICacheProvider cacheProvider, ICacheSettings settings, String methodType, String methodName, MethodDelegate <TResult> @delegate, params Object[] args)
        {
            // Default cache settings
            settings = settings ?? cacheProvider.DefaultSettings;

            #region Build CacheKey

            String cacheKey = settings.CacheKeyOverride;

            if (String.IsNullOrWhiteSpace(cacheKey))
            {
                cacheKey = cacheProvider.BuildCacheKey(String.Format("{0}.{1}", methodType, methodName), args);
            }

            #endregion

            settings.CacheKeyOverride = cacheKey;

            cacheProvider.DeleteCachedData <TResult>(settings, @delegate, args);
        }
 public ApplicationCache(ICacheSettings settings)
 {
     m_settings = settings;
 }
 public void DeleteCachedData <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult>(ICacheSettings settings, Func <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult> method, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16, params Object[] args)
 {
     this.DeleteCachedData_Proxy(
         settings,
         method.Method.DeclaringType.GetFriendlyTypeName(),
         method.Method.Name,
         ((Object[] argv) => (method.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16))),
         arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, args);
 }
Exemplo n.º 32
0
 public static TResult UpdateCachedData <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult>(this ICacheProvider cacheProvider, ICacheSettings settings, Func <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult> method, TResult data, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16, params Object[] args)
 {
     return(cacheProvider.UpdateCachedData_Proxy(
                settings,
                method.Method.DeclaringType.GetFriendlyTypeName(),
                method.Method.Name,
                ((Object[] argv) => (method.Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16))),
                data,
                arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, args));
 }