示例#1
0
        public bool CheckQuota(IServiceOperation <T> operation)
        {
            if (operation.Quota == null)
            {
                return(true);
            }

            var count = _cacheRepository.CountItems(operation.GetType().Name, DateTime.Now.Subtract(operation.Quota.Time));

            return(count <= operation.Quota.Requests);
        }
示例#2
0
        public void Add(string service, IServiceOperation <T> operation, string parameters, string result, bool hasErrored)
        {
            DateTime?expires = null;

            if (operation.Expiration != null)
            {
                expires = DateTime.Now.Add((TimeSpan)operation.Expiration);
            }

            var item = new Data.Entities.Cache()
            {
                Service    = service,
                Operation  = operation.GetType().Name,
                Params     = parameters,
                Result     = result,
                Created    = DateTime.Now,
                Expires    = expires,
                HasErrored = hasErrored
            };

            _context.Add(item);
            _context.SaveChanges();
        }