コード例 #1
0
        /// <summary>
        /// Removes outdated tiles from cache.
        /// </summary>
        private static void RemoveOutdatatedTiles(string filename, TilesMaxAge maxAge)
        {
            string date = GetSqliteStartDate(maxAge);

            if (string.IsNullOrWhiteSpace(date))
            {
                return;
            }

            try
            {
                using (var conn = new SQLiteConnection(string.Format(@"Data Source={0}", filename)))
                {
                    conn.Open();
                    using (var command = conn.CreateCommand())
                    {
                        command.CommandText = string.Format("DELETE FROM Tiles WHERE CacheTime < '{0}'", date);
                        command.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Current.Warn("Failed to remove outdated tiles from cache.", ex);
            }
        }
コード例 #2
0
        private static DateTime GetStartDate(TilesMaxAge maxAge)
        {
            var span = default(TimeSpan);

            switch (maxAge)
            {
            case TilesMaxAge.Month:
                span = new TimeSpan(-30, 0, 0, 0);
                break;

            case TilesMaxAge.Month3:
                span = new TimeSpan(-90, 0, 0, 0);
                break;

            case TilesMaxAge.Month6:
                span = new TimeSpan(-180, 0, 0, 0);
                break;

            case TilesMaxAge.Year:
                span = new TimeSpan(-365, 0, 0, 0);
                break;
            }
            if (span == default(TimeSpan))
            {
                return(default(DateTime));
            }
            return(DateTime.Now.Date.Add(span));
        }
コード例 #3
0
        private static string GetSqliteStartDate(TilesMaxAge maxAge)
        {
            if (maxAge == TilesMaxAge.Never)
            {
                return(string.Empty);
            }

            var date = GetStartDate(maxAge);

            if (date == default(DateTime))
            {
                return(string.Empty);
            }

            return(DateTimeSqLite(date));
        }
コード例 #4
0
        /// <summary>
        /// Removes outdated tiles and vaccums database.
        /// </summary>
        public static void InitDatabase(string filename, TilesMaxAge maxAge)
        {
            Logger.Current.Trace("In TileCacheHelper.InitDatabase()");
            if (_initialized)
            {
                return;
            }

            if (File.Exists(filename))
            {
                if (DebugHelper.CleanTileCache)
                {
                    RemoveOutdatatedTiles(filename, maxAge);

                    Vacuum(filename);
                }

                _initialized = true;
            }
        }