<commit_before>﻿namespace Showcase.Server.Infrastructure.Caching
{
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Threading.Tasks;

    using AutoMapper.QueryableExtensions;

    using Showcase.Server.DataTransferModels.Project;
    using Showcase.Server.DataTransferModels.Statistics;
    using Showcase.Server.Infrastructure.Caching.Base;
    using Showcase.Services.Data.Contracts;

    public class MemoryCacheService : BaseCacheService, ICacheService
    {
        private const string LatestProjectCacheKey = "LatestProjects";
        private const string PopularProjectCacheKey = "PopularProjects";
        private const string StatisticsCacheKey = "Statistics";

        private readonly IProjectsService projectsService;
        private readonly IStatisticsService statisticsService;

        public MemoryCacheService(IProjectsService projectsService, IStatisticsService statisticsService)
        {
            this.projectsService = projectsService;
            this.statisticsService = statisticsService;
        }

        public async Task<IEnumerable<ProjectSimpleResponseModel>> LatestProjects()
        {
            return await this.Get<IEnumerable<ProjectSimpleResponseModel>>(
                LatestProjectCacheKey, 
                async () => 
                    await this.projectsService
                        .LatestProjects()
                        .Project()
                        .To<ProjectSimpleResponseModel>()
                        .ToListAsync());
        }

        public async Task<IEnumerable<ProjectSimpleResponseModel>> PopularProjects()
        {
            return await this.Get<IEnumerable<ProjectSimpleResponseModel>>(
                PopularProjectCacheKey,
                async () =>
                    await this.projectsService
                        .MostPopular()
                        .Project()
                        .To<ProjectSimpleResponseModel>()
                        .ToListAsync());
        }

        public async Task<CurrentStatisticsResponseModel> Statistics()
        {
            return await this.Get<CurrentStatisticsResponseModel>(
                StatisticsCacheKey,
                async () => 
                    await this.statisticsService
                        .Current()
                        .Project()
                        .To<CurrentStatisticsResponseModel>()
                        .FirstOrDefaultAsync());
        }
    }
}<commit_msg>Added default cache minutes in MemoryCacheService.cs<commit_after>﻿namespace Showcase.Server.Infrastructure.Caching
{
    using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Threading.Tasks;

    using AutoMapper.QueryableExtensions;

    using Showcase.Server.DataTransferModels.Project;
    using Showcase.Server.DataTransferModels.Statistics;
    using Showcase.Server.Infrastructure.Caching.Base;
    using Showcase.Services.Data.Contracts;

    public class MemoryCacheService : BaseCacheService, ICacheService
    {
        private const int DefaultAbsoluteExpirationInMinutes = 15;

        private const string LatestProjectCacheKey = "LatestProjects";
        private const string PopularProjectCacheKey = "PopularProjects";
        private const string StatisticsCacheKey = "Statistics";

        private readonly IProjectsService projectsService;
        private readonly IStatisticsService statisticsService;

        public MemoryCacheService(IProjectsService projectsService, IStatisticsService statisticsService)
        {
            this.projectsService = projectsService;
            this.statisticsService = statisticsService;
        }

        public async Task<IEnumerable<ProjectSimpleResponseModel>> LatestProjects()
        {
            return await this.Get<IEnumerable<ProjectSimpleResponseModel>>(
                LatestProjectCacheKey,
                async () =>
                    await this.projectsService
                        .LatestProjects()
                        .Project()
                        .To<ProjectSimpleResponseModel>()
                        .ToListAsync(),
                DateTime.Now.AddMinutes(DefaultAbsoluteExpirationInMinutes));
        }

        public async Task<IEnumerable<ProjectSimpleResponseModel>> PopularProjects()
        {
            return await this.Get<IEnumerable<ProjectSimpleResponseModel>>(
                PopularProjectCacheKey,
                async () =>
                    await this.projectsService
                        .MostPopular()
                        .Project()
                        .To<ProjectSimpleResponseModel>()
                        .ToListAsync(),
                DateTime.Now.AddMinutes(DefaultAbsoluteExpirationInMinutes));
        }

        public async Task<CurrentStatisticsResponseModel> Statistics()
        {
            return await this.Get<CurrentStatisticsResponseModel>(
                StatisticsCacheKey,
                async () =>
                    await this.statisticsService
                        .Current()
                        .Project()
                        .To<CurrentStatisticsResponseModel>()
                        .FirstOrDefaultAsync(),
                DateTime.Now.AddMinutes(DefaultAbsoluteExpirationInMinutes));
        }
    }
}
{'fraction_non_alphanumeric': 0.06751927778822644, 'fraction_numerical': 0.0003761519653940192, 'mean_word_length': 1.9478935698447895, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4266292', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1116, 'n_words': 215}