Beispiel #1
0
        public async Task RemoveAsync(string id)
        {
            Logger.LogDebug("Removing Recipe {Id} from cache", id);

            var oldNames = await CacheProxy.GetAsync(KeyRegistry.Recipes.Names, id);

            var batch = new List <IEntry>
            {
                new HashEntry(KeyRegistry.Recipes.Names, id),
                new SetEntry(KeyRegistry.Recipes.Vegan, id),
                new SetEntry(KeyRegistry.Recipes.IngredientId, id),
                new SetEntry(KeyRegistry.Recipes.OvernightPreparation, id),
                new SetEntry(KeyRegistry.Recipes.Region, id),
                new SetEntry(KeyRegistry.Recipes.Cuisine, id),
                new SetEntry(KeyRegistry.Recipes.SpiceLevel, id),
                new SetEntry(KeyRegistry.Recipes.TotalTime, id),
                new SetEntry(KeyRegistry.Recipes.Collection, id)
            };

            batch.AddRange(await CreateSearchPhrasesAsync(id, oldNames?.Split(Environment.NewLine) ?? new string[0], new string[0]));

            await CacheProxy.StoreAsync(batch);
        }
Beispiel #2
0
        public async Task StoreAsync(Recipe recipe)
        {
            Logger.LogDebug("Saving Recipe {Id} in cache", recipe.Id);

            var oldNames = await CacheProxy.GetAsync(KeyRegistry.Recipes.Names, recipe.Id);

            var vegan = true;   // Store if recipe is vegan

            foreach (var ingredientId in recipe.IngredientIds)
            {
                var ingredient = await _ingredientsCache.GetAsync(ingredientId);

                if (!ingredient.Vegan)
                {
                    vegan = false;
                    break;
                }
            }

            var batch = new List <IEntry>
            {
                new HashEntry(KeyRegistry.Recipes.Names, recipe.Id, string.Join(Environment.NewLine, recipe.Names)),
                new SetEntry(KeyRegistry.Recipes.Vegan, vegan, recipe.Id),
                new SetEntry(KeyRegistry.Recipes.IngredientId, recipe.IngredientIds, recipe.Id),
                new SetEntry(KeyRegistry.Recipes.OvernightPreparation, recipe.OvernightPreparation, recipe.Id),
                new SetEntry(KeyRegistry.Recipes.Region, recipe.Region, recipe.Id),
                new SetEntry(KeyRegistry.Recipes.Cuisine, recipe.Cuisine, recipe.Id),
                new SetEntry(KeyRegistry.Recipes.SpiceLevel, recipe.SpiceLevel.ToString(), recipe.Id),
                new SetEntry(KeyRegistry.Recipes.TotalTime, recipe.TotalTime.ToString(), recipe.Id),
                new SetEntry(KeyRegistry.Recipes.Collection, recipe.Collections, recipe.Id)
            };

            batch.AddRange(await CreateSearchPhrasesAsync(recipe.Id, oldNames?.Split(Environment.NewLine) ?? new string[0], recipe.Names));

            await CacheProxy.StoreAsync(batch);
        }