예제 #1
0
 public AssetViewModel(IEmailService emailService, ISqlService sqlService, IDistributedCacheWithSqlService cacheService, IHttpContextAccessor httpContextAccessor)
 {
     this._emailSender    = emailService;
     _sqlService          = sqlService as SqlService;
     _cacheService        = cacheService as DistributedCacheWithSql;
     _httpContextAccessor = httpContextAccessor;
 }
        //idistributed cache
        public static void Push <T>(this IDistributedCacheWithSqlService _cache, string key, T item, int expirationInHours = 1)
        {
            var json = JsonConvert.SerializeObject(item);

            _cache.SetString(key, json, new DistributedCacheEntryOptions
            {
                AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(expirationInHours)
            });
        }
        public static async Task <T> PullAsync <T>(this IDistributedCacheWithSqlService _cache, string key)
        {
            var json = await _cache.GetStringAsync(key);

            if (json == null)
            {
                return(default(T));
            }

            return(JsonConvert.DeserializeObject <T>(json));
        }
 public StarragPageModel(
     IEmailService emailService,
     ISqlService sqlService,
     IDistributedCacheWithSqlService cacheService,
     IHttpContextAccessor httpContextAccessor)
 {
     _emailSender         = emailService;
     _sqlService          = sqlService as SqlService;
     _cacheService        = cacheService as DistributedCacheWithSql;
     _httpContextAccessor = httpContextAccessor;
 }
        public static async Task PushAsync <T>(this IDistributedCacheWithSqlService _cache, string key, T item, int expirationInHours = 1)
        {
            try
            {
                var json = JsonConvert.SerializeObject(item);

                await _cache.SetStringAsync(key, json, new DistributedCacheEntryOptions
                {
                    AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(expirationInHours)
                });
            }
            catch (Exception ex)
            {
                await Task.FromException(ex);
            }
        }
예제 #6
0
 public AboutModel(
     UserManager <ApplicationUser> userManager,
     SignInManager <ApplicationUser> signInManager,
     IEmailService emailService,
     ISqlService sqlService,
     IDistributedCacheWithSqlService cacheService,
     IHttpContextAccessor httpContextAccessor
     )
 {
     _userManager         = userManager;
     _signInManager       = signInManager;
     _emailSender         = emailService;
     _sqlService          = sqlService as SqlService;
     _cacheService        = cacheService as DistributedCacheWithSql;
     _httpContextAccessor = httpContextAccessor;
 }
        public static T Pull <T>(this IDistributedCacheWithSqlService _cache, string key)
        {
            var json = _cache.GetString(key);

            return(JsonConvert.DeserializeObject <T>(json));
        }