protected virtual async Task SetCacheItemsAsync(
            Guid storeId, Guid userId,
            StoreOwnerCacheItem currentCacheItem)
        {
            var storeOwners = await StoreOwnerRepository.GetListByStoreIdAsync(storeId);

            Logger.LogDebug(
                $"Getting all store owner in store: {storeId}");

            Logger.LogDebug($"Setting the cache items. Count: {storeOwners.Count}");

            var cacheItems = new Dictionary <string, StoreOwnerCacheItem>();

            foreach (var storeOwner in storeOwners)
            {
                cacheItems.Add(CalculateCacheKey(storeOwner.StoreId, storeOwner.OwnerUserId),
                               new StoreOwnerCacheItem(true));

                if (storeOwner.OwnerUserId == userId && storeOwner.StoreId == storeId)
                {
                    currentCacheItem.IsOwner = true;
                }
            }

            await Cache.SetManyAsync(cacheItems);

            Logger.LogDebug($"Finished setting the cache items. Count: {storeOwners.Count}");
        }
        protected virtual async Task <StoreOwnerCacheItem> GetCacheItemAsync(Guid storeId, Guid userId)
        {
            var cacheKey = CalculateCacheKey(storeId, userId);

            Logger.LogDebug($"StoreOwnerStore.GetCacheItemAsync: {cacheKey}");

            var cacheItem = await Cache.GetAsync(cacheKey);

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

            Logger.LogDebug($"Not found in the cache: {cacheKey}");
            cacheItem = new StoreOwnerCacheItem(false);

            await SetCacheItemsAsync(storeId, userId, cacheItem);

            return(cacheItem);
        }
Exemplo n.º 3
0
 protected virtual string CalculateCacheKey(Guid storeId, Guid userId)
 {
     return(StoreOwnerCacheItem.CalculateCacheKey(storeId, userId));
 }