public class SizeLimitedFileBitmapTileCache : FileBitmapTileCache { private long totalSize; public SizeLimitedFileBitmapTileCache(string cacheDirectory, string cacheId) : base(cacheDirectory, cacheId) { LimitedSize = 100000000; } public double LimitedSize { get; set; } protected override void SaveTileCore(ThinkGeo.MapSuite.Core.Tile tile) { base.SaveTileCore(tile); TileMatrixCell cell = TileMatrix.GetCell(tile.BoundingBox.GetCenterPoint()); if (cell != null) { string fileCacheName = GetTileImageFileName(cell.Row, cell.Column, tile.Scale); if (File.Exists(fileCacheName)) { totalSize += new FileInfo(fileCacheName).Length; if (totalSize > LimitedSize) { // Do you logic here. } } } } private string GetTileImageFileName(long row, long column, double scale) { string tileImageFileName = CacheDirectory; if (!tileImageFileName.EndsWith(@"\", StringComparison.OrdinalIgnoreCase)) { tileImageFileName += @"\"; } //Append cacheId if (!string.IsNullOrEmpty(CacheId)) { tileImageFileName += CacheId + @"\"; } bool foundAproximiateScaleDirectory = false; if (Directory.Exists(CacheDirectory + "\\" + CacheId)) { string[] targetDirectories = Directory.GetDirectories(CacheDirectory + "\\" + CacheId, "*.*", SearchOption.TopDirectoryOnly); foreach (string targetDirectory in targetDirectories) { DirectoryInfo directoryInfo = new DirectoryInfo(targetDirectory); string scaleFolder = directoryInfo.Name; double targetDirectoryScale = Convert.ToDouble(scaleFolder, CultureInfo.InvariantCulture); if (Math.Abs(scale - targetDirectoryScale) < 1e-4) { tileImageFileName = targetDirectory + @"\"; foundAproximiateScaleDirectory = true; break; } } } if (!foundAproximiateScaleDirectory) { tileImageFileName += scale.ToString(CultureInfo.InvariantCulture) + @"\"; } //Append row tileImageFileName += row.ToString(CultureInfo.InvariantCulture) + @"\"; //Append column tileImageFileName += column.ToString(CultureInfo.InvariantCulture); //Append extension string extension = ImageFormat.ToString().ToLowerInvariant(); tileImageFileName += "." + extension; return tileImageFileName; } }