Пример #1
0
        public async Task <MenuGrantCacheItem> CheckAsync(Guid menuId, string providerName, string providerKey)
        {
            var cacheKey = MenuGrantCacheItem.CalculateCacheKey(menuId, providerName, providerKey);

            _logger.LogDebug("MenuGrantCheckerCache.CheckAsync: {cacheKey}", cacheKey);

            var cacheItem = await _cache.GetAsync(cacheKey);

            if (cacheItem != null)
            {
                _logger.LogDebug("Found in the cache: {cacheKey}", cacheKey);
                return(cacheItem);
            }

            _logger.LogDebug("Not found in the cache, getting from the repository: {cacheKey}", cacheKey);

            cacheItem = new MenuGrantCacheItem(
                menuId,
                (await _menuGrantRepository.FindAsync(menuId, providerName, providerKey)) != null
                );

            _logger.LogDebug("Setting the cache item: {cacheKey}", cacheKey);

            await _cache.SetAsync(
                cacheKey,
                cacheItem
                );

            _logger.LogDebug("Finished setting the cache item: {cacheKey}", cacheKey);

            return(cacheItem);
        }
 protected virtual string CalculateCacheKey(
     Guid menuId,
     string providerName,
     string providerKey
     )
 {
     return(MenuGrantCacheItem.CalculateCacheKey(menuId, providerName, providerKey));
 }