Beispiel #1
0
 public RedisCacheManager(IRedisConnectionWrapper redisConnectionWrapper,
                          IMemoryCacheManager memoryCacheManager)
 {
     _redisConnectionWrapper = redisConnectionWrapper;
     _memoryCacheManager     = memoryCacheManager;
     this._db = _redisConnectionWrapper.Database();
 }
Beispiel #2
0
        protected override int GetCurrentPressure()
        {
            int  num  = GC.CollectionCount(2);
            SRef ref2 = this._sizedRef;

            if ((num != this._gen2Count) && (ref2 != null))
            {
                this._gen2Count = num;
                this._idx      ^= 1;
                this._cacheSizeSampleTimes[this._idx] = DateTime.UtcNow;
                this._cacheSizeSamples[this._idx]     = ref2.ApproximateSize;
                IMemoryCacheManager manager = s_memoryCacheManager;
                if (manager != null)
                {
                    manager.UpdateCacheSize(this._cacheSizeSamples[this._idx], this._memoryCache);
                }
            }
            if (this._memoryLimit <= 0L)
            {
                return(0);
            }
            long num2 = this._cacheSizeSamples[this._idx];

            if (num2 > this._memoryLimit)
            {
                num2 = this._memoryLimit;
            }
            return((int)((num2 * 100L) / this._memoryLimit));
        }
Beispiel #3
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="memoryCacheManager">内存缓存</param>
 /// <param name="redisCacheManager">redis</param>
 /// <param name="loggerFactory"></param>
 public DefaultHybridCacheManager(IMemoryCacheManager memoryCacheManager, IRedisCacheManager redisCacheManager, ILoggerFactory loggerFactory)
 {
     _providers = new List <IHybridCacheProvider> {
         memoryCacheManager, redisCacheManager
     };
     _loggerLazy = new Lazy <ILogger>(() => loggerFactory?.CreateLogger <DefaultHybridCacheManager>() ?? NullLogger <DefaultHybridCacheManager> .Instance);
 }
Beispiel #4
0
 public BaseService(IBaseCRUDRepository <TEntity> repository, IMemoryCacheManager memoryCacheManager,
                    IMapper mapper, IConfiguration configuration)
 {
     _repository         = repository;
     _mapperDependency   = mapper;
     _configuration      = configuration;
     _memoryCacheManager = memoryCacheManager;
 }
Beispiel #5
0
 public ContentController(IContentRepository contentRepository, ICategoryRepository categoryRepository, IUserRepository userRepository, IMediaItemRepository mediaItemRepository, IMemoryCacheManager cacheManager)
 {
     _contentRepository   = contentRepository;
     _categoryRepository  = categoryRepository;
     _userRepository      = userRepository;
     _mediaItemRepository = mediaItemRepository;
     _cacheManager        = cacheManager;
 }
Beispiel #6
0
        public VBRequestPOExternalService(PurchasingDbContext dbContext, IServiceProvider serviceProvider)
        {
            _dbContext        = dbContext;
            _identityService  = serviceProvider.GetService <IdentityService>();
            _cacheManager     = serviceProvider.GetService <IMemoryCacheManager>();
            _currencyProvider = serviceProvider.GetService <ICurrencyProvider>();

            _serviceProvider = serviceProvider;
        }
        public static T Set <T>(this IMemoryCacheManager cache, object key, T value)
        {
            var entry = cache.CreateEntry(key);

            entry.Value = value;
            entry.Dispose();

            return(value);
        }
Beispiel #8
0
 public PPHBankExpenditureNoteFacade(PurchasingDbContext dbContext, IBankDocumentNumberGenerator bankDocumentNumberGenerator, IServiceProvider serviceProvider)
 {
     this.dbContext = dbContext;
     this.dbSet     = dbContext.Set <PPHBankExpenditureNote>();
     this.dbSetPurchasingDocumentExpedition = dbContext.Set <PurchasingDocumentExpedition>();
     this.bankDocumentNumberGenerator       = bankDocumentNumberGenerator;
     _serviceProvider = serviceProvider;
     _cacheManager    = (IMemoryCacheManager)serviceProvider.GetService(typeof(IMemoryCacheManager));
 }
        protected override int GetCurrentPressure()
        {
            // Call GetUpdatedTotalCacheSize to update the total
            // cache size, if there has been a recent Gen 2 Collection.
            // This update must happen, otherwise the CacheManager won't
            // know the total cache size.
            int          gen2Count = GC.CollectionCount(2);
            SRefMultiple sref      = _sizedRefMultiple;

            if (gen2Count != _gen2Count && sref != null)
            {
                // update _gen2Count
                _gen2Count = gen2Count;

                // the SizedRef is only updated after a Gen2 Collection

                // increment the index (it's either 1 or 0)
                Dbg.Assert(SAMPLE_COUNT == 2);
                _idx = _idx ^ 1;
                // remember the sample time
                _cacheSizeSampleTimes[_idx] = DateTime.UtcNow;
                // remember the sample value
                _cacheSizeSamples[_idx] = sref.ApproximateSize;
#if DBG
                Dbg.Trace("MemoryCacheStats", "SizedRef.ApproximateSize=" + _cacheSizeSamples[_idx]);
#endif
                IMemoryCacheManager memoryCacheManager = s_memoryCacheManager;
                if (memoryCacheManager != null)
                {
                    memoryCacheManager.UpdateCacheSize(_cacheSizeSamples[_idx], _memoryCache);
                }
            }

            // if there's no memory limit, then there's nothing more to do
            if (_memoryLimit <= 0)
            {
                return(0);
            }

            long cacheSize = _cacheSizeSamples[_idx];

            // use _memoryLimit as an upper bound so that pressure is a percentage (between 0 and 100, inclusive).
            if (cacheSize > _memoryLimit)
            {
                cacheSize = _memoryLimit;
            }

            // PerfCounter: Cache Percentage Process Memory Limit Used
            //    = memory used by this process / process memory limit at pressureHigh
            // Set private bytes used in kilobytes because the counter is a DWORD

            //


            int result = (int)(cacheSize * 100 / _memoryLimit);
            return(result);
        }
Beispiel #10
0
 public MenuService(IUnitOfWork unitOfWork
                    , IMemoryCacheManager memoryCacheManager
                    , IEnumReferenceService enumReferenceService
                    , IRepository <sys_Menu> repoMenu)
 {
     this._unitOfWork           = unitOfWork;
     this._memoryCacheManager   = memoryCacheManager;
     this._enumReferenceService = enumReferenceService;
     this._repoMenu             = repoMenu;
 }
        public static T Set <T>(this IMemoryCacheManager cache, object key, T value, TimeSpan absoluteExpirationRelativeToNow)
        {
            var entry = cache.CreateEntry(key);

            entry.AbsoluteExpirationRelativeToNow = absoluteExpirationRelativeToNow;
            entry.Value = value;
            entry.Dispose();

            return(value);
        }
        public static T Set <T>(this IMemoryCacheManager cache, object key, T value, DateTimeOffset absoluteExpiration)
        {
            var entry = cache.CreateEntry(key);

            entry.AbsoluteExpiration = absoluteExpiration;
            entry.Value = value;
            entry.Dispose();

            return(value);
        }
        public GraphAuthentication(IOptions <GraphDetails> graph, IMemoryCacheManager memoryCacheManager)
        {
            var options = graph.Value;

            _host               = options.Host;
            _tenant             = options.Tenant;
            _client_id          = options.Client_Id;
            _client_secret      = options.Client_Secret;
            _scope              = options.Scope;
            _memoryCacheManager = memoryCacheManager;
        }
        public static TItem GetOrCreate <TItem>(this IMemoryCacheManager cache, object key, Func <ICacheEntry, TItem> factory)
        {
            if (!cache.TryGetValue(key, out var result))
            {
                var entry = cache.CreateEntry(key);
                result = factory(entry);
                entry.SetValue(result);
                entry.Dispose();
            }

            return((TItem)result);
        }
        public static async Task <TItem> GetOrCreateAsync <TItem>(this IMemoryCacheManager cache, object key, Func <ICacheEntry, Task <TItem> > factory)
        {
            if (!cache.TryGetValue(key, out object result))
            {
                var entry = cache.CreateEntry(key);
                result = await factory(entry);

                entry.SetValue(result);
                entry.Dispose();
            }

            return((TItem)result);
        }
        public GetMonitoringLoadingQueryHandler(IStorage storage, IServiceProvider serviceProvider)
        {
            _storage = storage;
            garmentCuttingOutRepository     = storage.GetRepository <IGarmentCuttingOutRepository>();
            garmentCuttingOutItemRepository = storage.GetRepository <IGarmentCuttingOutItemRepository>();
            garmentLoadingRepository        = storage.GetRepository <IGarmentLoadingRepository>();
            garmentLoadingItemRepository    = storage.GetRepository <IGarmentLoadingItemRepository>();
            garmentPreparingRepository      = storage.GetRepository <IGarmentPreparingRepository>();
            garmentPreparingItemRepository  = storage.GetRepository <IGarmentPreparingItemRepository>();
            _http = serviceProvider.GetService <IHttpClientService>();

            cacheManager = serviceProvider.GetService <IMemoryCacheManager>();
        }
Beispiel #17
0
 public static T Get <T>(this IMemoryCacheManager cacheManager, string key, Func <T> acquire, int cacheTime = 60)
 {
     if (cacheManager.IsSet(key))
     {
         return(cacheManager.Get <T>(key));
     }
     else
     {
         var result = acquire();
         cacheManager.Set(key, result, cacheTime);
         return(result);
     }
 }
        public static T Set <T>(this IMemoryCacheManager cache, object key, T value, MemoryCacheEntryOptions options)
        {
            using (var entry = cache.CreateEntry(key))
            {
                if (options != null)
                {
                    entry.SetOptions(options);
                }

                entry.Value = value;
            }

            return(value);
        }
Beispiel #19
0
        public void Dispose()
        {
            SRefMultiple sref = _sizedRefMultiple;

            if (sref != null && Interlocked.CompareExchange(ref _sizedRefMultiple, null, sref) == sref)
            {
                sref.Dispose();
            }
            IMemoryCacheManager memoryCacheManager = s_memoryCacheManager;

            if (memoryCacheManager != null)
            {
                memoryCacheManager.ReleaseCache(_memoryCache);
            }
        }
Beispiel #20
0
        public void Dispose()
        {
            SRef comparand = this._sizedRef;

            if ((comparand != null) && (Interlocked.CompareExchange <SRef>(ref this._sizedRef, null, comparand) == comparand))
            {
                comparand.Dispose();
            }
            IMemoryCacheManager manager = s_memoryCacheManager;

            if (manager != null)
            {
                manager.ReleaseCache(this._memoryCache);
            }
        }
Beispiel #21
0
 private static void InitMemoryCacheManager()
 {
     if (s_memoryCacheManager == null)
     {
         IMemoryCacheManager memoryCacheManager = null;
         IServiceProvider    host = ObjectCache.Host;
         if (host != null)
         {
             memoryCacheManager = host.GetService(typeof(IMemoryCacheManager)) as IMemoryCacheManager;
         }
         if (memoryCacheManager != null)
         {
             Interlocked.CompareExchange(ref s_memoryCacheManager, memoryCacheManager, null);
         }
     }
 }
Beispiel #22
0
 public RoleService(IUnitOfWork unitOfWork
                    , IMemoryCacheManager memoryCacheManager
                    , IRepository <sys_RoleMenu> repoRoleMenu
                    , IRepository <sys_Menu> repoMenu
                    , IRepository <sys_RolePermission> repoRolePermission
                    , IRepository <sys_UserRole> repoUserRole
                    , IRepository <sys_Role> repoRole)
 {
     this._memoryCacheManager = memoryCacheManager;
     this._repoRole           = repoRole;
     this._repoRoleMenu       = repoRoleMenu;
     this._repoMenu           = repoMenu;
     this._repoUserRole       = repoUserRole;
     this._repoRolePermission = repoRolePermission;
     this._unitOfWork         = unitOfWork;
 }
Beispiel #23
0
 public GetCategoriesHandler(IUnitOfWork unitOfWork,
                             IMemoryCacheManager memoryCacheManager)
     : base(unitOfWork)
 {
     _memoryCacheManager = memoryCacheManager;
 }
Beispiel #24
0
 public CoreData(ICoreHttpClientService http, IMemoryCacheManager cacheManager)
 {
     _http         = http;
     _cacheManager = cacheManager;
 }
Beispiel #25
0
 public MemoryInterceptorCacheHandler(IMemoryCacheManager cacheManager, ICacheExpiration cacheExpiration) : base(cacheManager, cacheExpiration)
 {
 }
 public MemoryCacheFilesService(IMemoryCacheManager cacheManager)
 {
     this.cacheManager = cacheManager;
 }
 public CoreData(IServiceProvider serviceProvider)
 {
     _http         = serviceProvider.GetService <ICoreHttpClientService>();
     _cacheManager = serviceProvider.GetService <IMemoryCacheManager>();
 }
 public CoreClient(IHttpClientService http, IServiceProvider serviceProvider)
 {
     _http        = http;
     cacheManager = serviceProvider.GetService <IMemoryCacheManager>();
     Token        = GetTokenAsync().Result;
 }