Exemplo n.º 1
0
 private async Task <T> GetStatWithCacheAsync <T>(
     string key,
     StatsCache <T> cache,
     Func <SQLiteConnection, SQLiteTransaction, string, Task <T> > getEntityFunc) where T : class, ICacheable
 {
     return(await cache.GetValueAsync(key, k => ExecuteQueryAsync(getEntityFunc, k)));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Конструктор класса базы данных
        /// </summary>
        /// <param name="dataSource">Путь к базе данных</param>
        /// <param name="cacheTime">Время актуальности значений в кэше в секундах</param>
        /// <param name="maxCountItemsInReport">Максимальное количество элементов в отчете Reports</param>
        public Database(string dataSource, int cacheTime, int maxCountItemsInReport)
        {
            this.maxCountItemsInReport = maxCountItemsInReport;

            connectionString =
                new SQLiteConnectionStringBuilder
            {
                DataSource     = dataSource,
                Version        = 3,
                SyncMode       = SynchronizationModes.Normal,
                JournalMode    = SQLiteJournalModeEnum.Wal,
                DateTimeKind   = DateTimeKind.Utc,
                DateTimeFormat = SQLiteDateFormats.ISO8601
            }.ConnectionString;

            recentMathcesCache  = new ReportCache <Match>(cacheTime);
            bestPlayersCache    = new ReportCache <BestPlayer>(cacheTime);
            popularServersCache = new ReportCache <PopularServer>(cacheTime);
            serverStatCache     = new StatsCache <ServerStat>(cacheTime);
            playerStatCache     = new StatsCache <PlayerStat>(cacheTime);

            Init();
        }