Here is the source code in my plug-in module - this might help to make it a little clearer what i am doing thought it wont help much in reproducing the issue. It would surprise me though if the server side cache was working for you since i don’t think i am doing anything unusual as far as how i am using it.
using System;
using System.Web;
using System.Web.Caching;
using System.Threading;
using System.IO;
using System.Text;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Drawing;
using System.Collections.Generic;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WmsServerEdition;
using UPSLT.RTS.Server.RoadNetwork.Data;
using UPSLT.Base.Spatial;
namespace RTSPlugin {
public class RTSMap : WmsLayerPlugin
{
private static NetworkDataStore _cachedDataStore = new NetworkDataStore(@“C:\Maps\TANA2009.6RN8”);
private static bool initialized = false;
private static RTSMapLog _mapLog = new RTSMapLog();
private static Dictionary<string, Feature> _featureCache = new Dictionary<string, Feature>();
public RTSMap()
{
RTSMapLog mapLog = new RTSMapLog();
mapLog.Log(@"C:\WMSServerLogs", “Initializing…”);
/*
if (!initialized)
{
_cachedDataStore.Initialize();
initialized = true;
RTSMapLog mapLog = new RTSMapLog();
mapLog.Log(@"C:\WMSServerLogs", “Initializing…”);
}
*/
}
protected static void CacheItemRemoved(string key, object o, CacheItemRemovedReason reason)
{
RTSDataStore removedDataStore = (RTSDataStore)o;
removedDataStore.ClearFeatureCollections();
removedDataStore = null;
}
protected override MapConfiguration GetMapConfigurationCore(string style, string crs)
{
MapConfiguration mapConfiguration = new MapConfiguration();
mapConfiguration.TileCache = new FileBitmapTileCache(@“C:\BitmapTileCache”);
switch (style)
{
case “DEFAULT”:
AddDefaultLayers(mapConfiguration.Layers, RTSMapInitialization.StyleType.Default);
mapConfiguration.TileCache.TileAccessMode = TileAccessMode.ReadOnly;
break;
case “SATELLITE”:
AddSatelliteLayers(mapConfiguration.Layers, RTSMapInitialization.StyleType.Satellite);
mapConfiguration.TileCache.TileAccessMode = TileAccessMode.ReadOnly;
break;
case “CACHE”:
AddDefaultLayers(mapConfiguration.Layers, RTSMapInitialization.StyleType.Cached);
mapConfiguration.TileCache.TileAccessMode = TileAccessMode.ReadAddDelete;
break;
default:
AddDefaultLayers(mapConfiguration.Layers, RTSMapInitialization.StyleType.Default);
mapConfiguration.TileCache.TileAccessMode = TileAccessMode.ReadOnly;
break;
}
return mapConfiguration;
}
protected override Bitmap GetMapCore(GetMapRequest getMapRequest, MapConfiguration mapConfiguration, HttpContext context)
{
DateTime startTime = DateTime.Now;
RTSMapLog mapLog = new RTSMapLog();
NameValueCollection queryString = context.Request.QueryString;
string mapExtentKey = queryString[“MapExtent”];
if (mapExtentKey == null)
{
mapExtentKey = new RectangleShape(-123.097872617701, 44.6638374044447,
-122.324772617701, 43.8907374044447).GetWellKnownText();
//mapExtentKey = new RectangleShape(-76.615411, 39.295277, -76.610031, 39.29167).GetWellKnownText();
}
RTSDataStore dataStore;
//MapConfiguration configuration = new MapConfiguration();
switch (getMapRequest.Styles[0])
{
case “DEFAULT”:
//configuration.TileCache = mapConfiguration.TileCache;
dataStore = GetMapRequestDataStore(mapExtentKey, context, RTSMapInitialization.StyleType.Default);
//AddDefaultLayers(configuration.Layers, dataStore, RTSMapInitialization.StyleType.Default);
SetDataStoreForAllLayers(dataStore, mapConfiguration.Layers);
break;
case “SATELLITE”:
dataStore = GetMapRequestDataStore(mapExtentKey, context, RTSMapInitialization.StyleType.Satellite);
//AddSatelliteLayers(configuration.Layers, dataStore);
SetDataStoreForAllLayers(dataStore, mapConfiguration.Layers);
break;
case “CACHE”:
//configuration.TileCache = mapConfiguration.TileCache;
dataStore = GetMapRequestDataStore(mapExtentKey, context, RTSMapInitialization.StyleType.Cached);
//AddDefaultLayers(configuration.Layers, /* dataStore,*/ RTSMapInitialization.StyleType.Cached);
SetDataStoreForAllLayers(dataStore, mapConfiguration.Layers);
break;
default:
dataStore = GetMapRequestDataStore(mapExtentKey, context, RTSMapInitialization.StyleType.Default);
//AddDefaultLayers(configuration.Layers, dataStore, RTSMapInitialization.StyleType.Default);
SetDataStoreForAllLayers(dataStore, mapConfiguration.Layers);
break;
}
Bitmap tileBitmap = base.GetMapCore(getMapRequest, mapConfiguration /*configuration*/, context);
DateTime endTime = DateTime.Now;
TimeSpan duration = endTime.Subtract(startTime);
int timeInMS = (duration .Seconds * 1000) + duration .Milliseconds;
mapLog.Log(@"C:\WMSServerLogs", "Total Rendering Time: " + timeInMS.ToString());
return tileBitmap;
}
protected override RectangleShape GetBoundingBoxCore(string crs)
{
Proj4Projection proj4 = new Proj4Projection();
proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
proj4.Open();
//Vertex llPoint = proj4.ConvertToExternalProjection(-76.615411, 39.29167);
//Vertex urPoint = proj4.ConvertToExternalProjection(-76.610031, 39.295277);
// -123.097872617701, 44.6638374044447, -122.324772617701, 43.8907374044447
Vertex llPoint = proj4.ConvertToExternalProjection(-123.097872617701, 43.8907374044447);
Vertex urPoint = proj4.ConvertToExternalProjection(-122.324772617701, 44.6638374044447);
proj4.Close();
RectangleShape mapBounds = new RectangleShape(llPoint.X, urPoint.Y,
urPoint.X, llPoint.Y);
return mapBounds;
}
protected override Collection<WmsLayerStyle> GetStylesCore()
{
Collection<WmsLayerStyle> styles = new Collection<WmsLayerStyle>();
styles.Add(new WmsLayerStyle(“DEFAULT”));
styles.Add(new WmsLayerStyle(“SATELLITE”));
styles.Add(new WmsLayerStyle(“CACHE”));
return styles;
}
protected override Collection<string> GetProjectionsCore()
{
Collection<string> projections = new Collection<string>();
projections.Add(“EPSG:4326”);
projections.Add(“EPSG:900913”);
return projections;
}
protected override GeographyUnit GetGeographyUnitCore(string projectionName)
{
return GeographyUnit.Meter;
}
protected override string GetNameCore()
{
return GetType().Name;
}
private Proj4Projection CreateMercatorProjection()
{
Proj4Projection proj4 = new Proj4Projection();
proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
return proj4;
}
private static RTSDataStore GetMapRequestDataStore(string mapExtentKey, HttpContext context,
RTSMapInitialization.StyleType style)
{
int cacheExpiration = 20;
RTSDataStore dataStore;
if (context.Cache[mapExtentKey] != null)
{
dataStore = (RTSDataStore)context.Cache[mapExtentKey];
}
else
{
RectangleShape mapExtent = new RectangleShape(mapExtentKey);
if (style == RTSMapInitialization.StyleType.Cached) mapExtent.ScaleUp(0);
else mapExtent.ScaleUp(80);
dataStore = new RTSDataStore(_cachedDataStore, mapExtent, style);
// need more time for pre-rendered tiles
if (style == RTSMapInitialization.StyleType.Cached) cacheExpiration = 30;
try
{
// TODO - reset cache expiration to 20 seconds
CacheItemRemovedCallback cacheItemRemoveCallback = new CacheItemRemovedCallback(CacheItemRemoved);
context.Cache.Add(mapExtentKey, dataStore, null, DateTime.Now.AddSeconds(cacheExpiration),
TimeSpan.Zero, CacheItemPriority.Default, cacheItemRemoveCallback);
}
catch (System.Exception e)
{
dataStore = (RTSDataStore)context.Cache[mapExtentKey];
}
}
return dataStore;
}
private RTSDataStore GetLegacyDataStore(RectangleShape mapExtent)
{
RTSDataStore dataStore = new RTSDataStore(_cachedDataStore, mapExtent, RTSMapInitialization.StyleType.Default);
return dataStore;
}
private void AddDefaultLayers(GeoCollection<Layer> layers, RTSDataStore dataStore, RTSMapInitialization.StyleType style)
{
InMemoryFeatureLayer outerZoomLevel0Layer = new RTSFeatureLayer(FeatureType.Streets, “LEVEL0”, dataStore);
InMemoryFeatureLayer highwayShieldLevel0Layer = new RTSFeatureLayer(FeatureType.Streets, “LEVEL0”, dataStore);
InMemoryFeatureLayer outerZoomLevel1Layer = new RTSFeatureLayer(FeatureType.Streets, “LEVEL1”, dataStore);
InMemoryFeatureLayer highwayShieldLevel1Layer = new RTSFeatureLayer(FeatureType.Streets, “LEVEL1”, dataStore);
InMemoryFeatureLayer outerZoomLevel2Layer = new RTSFeatureLayer(FeatureType.Streets, “OUTERZOOMLEVEL2”, dataStore);
InMemoryFeatureLayer innerZoomLevel2Layer = new RTSFeatureLayer(FeatureType.Streets, “INNERZOOMLEVEL2”, dataStore);
InMemoryFeatureLayer innerZoomLevel3Layer = new RTSFeatureLayer(FeatureType.Streets, “INNERZOOMLEVEL3”, dataStore);
InMemoryFeatureLayer polygonDetail0Layer = new RTSFeatureLayer(FeatureType.Polygons, “LEVEL0”, dataStore);
InMemoryFeatureLayer polygonDetail1Layer = new RTSFeatureLayer(FeatureType.Polygons, “LEVEL1”, dataStore);
InMemoryFeatureLayer polygonDetail2Layer = new RTSFeatureLayer(FeatureType.Polygons, “LEVEL2”, dataStore);
InMemoryFeatureLayer polygonDetail3Layer = new RTSFeatureLayer(FeatureType.Polygons, “LEVEL3”, dataStore);
InMemoryFeatureLayer polygonDetail4Layer = new RTSFeatureLayer(FeatureType.Polygons, “LEVEL4”, dataStore);
Proj4Projection proj4 = new Proj4Projection();
proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
innerZoomLevel2Layer.FeatureSource.Projection = proj4;
outerZoomLevel2Layer.FeatureSource.Projection = proj4;
outerZoomLevel1Layer.FeatureSource.Projection = proj4;
outerZoomLevel0Layer.FeatureSource.Projection = proj4;
highwayShieldLevel1Layer.FeatureSource.Projection = proj4;
highwayShieldLevel0Layer.FeatureSource.Projection = proj4;
polygonDetail0Layer.FeatureSource.Projection = proj4;
polygonDetail1Layer.FeatureSource.Projection = proj4;
polygonDetail2Layer.FeatureSource.Projection = proj4;
polygonDetail3Layer.FeatureSource.Projection = proj4;
polygonDetail4Layer.FeatureSource.Projection = proj4;
RTSMapInitialization.InitializeDetailLevel0(outerZoomLevel0Layer, style);
RTSMapInitialization.InitializeHwyShieldLevel0(highwayShieldLevel0Layer, style);
RTSMapInitialization.InitializeDetailLevel1(outerZoomLevel1Layer, RTSMapInitialization.StyleType.Default);
RTSMapInitialization.InitializeHwyShieldLevel1(highwayShieldLevel1Layer, style);
RTSMapInitialization.InitializeOuterZoomDetailLevel2(outerZoomLevel2Layer, RTSMapInitialization.StyleType.Default);
RTSMapInitialization.InitializeInnerZoomDetailLevel2(innerZoomLevel2Layer, RTSMapInitialization.StyleType.Default);
RTSMapInitialization.InitializePolygonLevels(polygonDetail0Layer, polygonDetail1Layer,
polygonDetail2Layer, polygonDetail3Layer,
polygonDetail4Layer, style);
layers.Add(polygonDetail0Layer);
layers.Add(polygonDetail1Layer);
layers.Add(polygonDetail2Layer);
layers.Add(polygonDetail3Layer);
layers.Add(polygonDetail4Layer);
layers.Add(innerZoomLevel2Layer);
layers.Add(outerZoomLevel2Layer);
layers.Add(outerZoomLevel1Layer);
layers.Add(outerZoomLevel0Layer);
layers.Add(highwayShieldLevel1Layer);
layers.Add(highwayShieldLevel0Layer);
}
private void AddDefaultLayers(GeoCollection<Layer> layers, RTSMapInitialization.StyleType style)
{
InMemoryFeatureLayer outerZoomLevel0Layer = new RTSFeatureLayer(FeatureType.Streets, “LEVEL0”);
InMemoryFeatureLayer highwayShieldLevel0Layer = new RTSFeatureLayer(FeatureType.Streets, “LEVEL0”);
InMemoryFeatureLayer outerZoomLevel1Layer = new RTSFeatureLayer(FeatureType.Streets, “LEVEL1”);
InMemoryFeatureLayer highwayShieldLevel1Layer = new RTSFeatureLayer(FeatureType.Streets, “LEVEL1”);
InMemoryFeatureLayer outerZoomLevel2Layer = new RTSFeatureLayer(FeatureType.Streets, “OUTERZOOMLEVEL2”);
InMemoryFeatureLayer innerZoomLevel2Layer = new RTSFeatureLayer(FeatureType.Streets, “INNERZOOMLEVEL2”);
InMemoryFeatureLayer innerZoomLevel3Layer = new RTSFeatureLayer(FeatureType.Streets, “INNERZOOMLEVEL3”);
InMemoryFeatureLayer polygonDetail0Layer = new RTSFeatureLayer(FeatureType.Polygons, “LEVEL0”);
InMemoryFeatureLayer polygonDetail1Layer = new RTSFeatureLayer(FeatureType.Polygons, “LEVEL1”);
InMemoryFeatureLayer polygonDetail2Layer = new RTSFeatureLayer(FeatureType.Polygons, “LEVEL2”);
InMemoryFeatureLayer polygonDetail3Layer = new RTSFeatureLayer(FeatureType.Polygons, “LEVEL3”);
InMemoryFeatureLayer polygonDetail4Layer = new RTSFeatureLayer(FeatureType.Polygons, “LEVEL4”);
Proj4Projection proj4 = new Proj4Projection();
proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
innerZoomLevel2Layer.FeatureSource.Projection = proj4;
outerZoomLevel2Layer.FeatureSource.Projection = proj4;
outerZoomLevel1Layer.FeatureSource.Projection = proj4;
outerZoomLevel0Layer.FeatureSource.Projection = proj4;
highwayShieldLevel1Layer.FeatureSource.Projection = proj4;
highwayShieldLevel0Layer.FeatureSource.Projection = proj4;
polygonDetail0Layer.FeatureSource.Projection = proj4;
polygonDetail1Layer.FeatureSource.Projection = proj4;
polygonDetail2Layer.FeatureSource.Projection = proj4;
polygonDetail3Layer.FeatureSource.Projection = proj4;
polygonDetail4Layer.FeatureSource.Projection = proj4;
RTSMapInitialization.InitializeDetailLevel0(outerZoomLevel0Layer, style);
RTSMapInitialization.InitializeHwyShieldLevel0(highwayShieldLevel0Layer, style);
RTSMapInitialization.InitializeDetailLevel1(outerZoomLevel1Layer, style);
RTSMapInitialization.InitializeHwyShieldLevel1(highwayShieldLevel1Layer, style);
RTSMapInitialization.InitializeOuterZoomDetailLevel2(outerZoomLevel2Layer, style);
RTSMapInitialization.InitializeInnerZoomDetailLevel2(innerZoomLevel2Layer, style);
RTSMapInitialization.InitializePolygonLevels(polygonDetail0Layer, polygonDetail1Layer,
polygonDetail2Layer, polygonDetail3Layer,
polygonDetail4Layer, style);
layers.Add(polygonDetail0Layer);
layers.Add(polygonDetail1Layer);
layers.Add(polygonDetail2Layer);
layers.Add(polygonDetail3Layer);
layers.Add(polygonDetail4Layer);
layers.Add(innerZoomLevel2Layer);
layers.Add(outerZoomLevel2Layer);
layers.Add(outerZoomLevel1Layer);
layers.Add(outerZoomLevel0Layer);
layers.Add(highwayShieldLevel1Layer);
layers.Add(highwayShieldLevel0Layer);
}
private void AddSatelliteLayers(GeoCollection<Layer> layers, RTSMapInitialization.StyleType style)
{
InMemoryFeatureLayer outerZoomLevel0Layer = new RTSFeatureLayer(FeatureType.Streets, “LEVEL0”);
InMemoryFeatureLayer highwayShieldLevel0Layer = new RTSFeatureLayer(FeatureType.Streets, “LEVEL0”);
InMemoryFeatureLayer outerZoomLevel1Layer = new RTSFeatureLayer(FeatureType.Streets, “LEVEL1”);
InMemoryFeatureLayer highwayShieldLevel1Layer = new RTSFeatureLayer(FeatureType.Streets, “LEVEL1”);
InMemoryFeatureLayer outerZoomLevel2Layer = new RTSFeatureLayer(FeatureType.Streets, “OUTERZOOMLEVEL2”);
InMemoryFeatureLayer innerZoomLevel2Layer = new RTSFeatureLayer(FeatureType.Streets, “INNERZOOMLEVEL2”);
InMemoryFeatureLayer innerZoomLevel3Layer = new RTSFeatureLayer(FeatureType.Streets, “INNERZOOMLEVEL3”);
Proj4Projection proj4 = new Proj4Projection();
proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
innerZoomLevel2Layer.FeatureSource.Projection = proj4;
outerZoomLevel2Layer.FeatureSource.Projection = proj4;
outerZoomLevel1Layer.FeatureSource.Projection = proj4;
outerZoomLevel0Layer.FeatureSource.Projection = proj4;
highwayShieldLevel1Layer.FeatureSource.Projection = proj4;
highwayShieldLevel0Layer.FeatureSource.Projection = proj4;
RTSMapInitialization.InitializeDetailLevel0(outerZoomLevel0Layer, RTSMapInitialization.StyleType.Satellite);
RTSMapInitialization.InitializeHwyShieldLevel0(highwayShieldLevel0Layer, RTSMapInitialization.StyleType.Satellite);
RTSMapInitialization.InitializeDetailLevel1(outerZoomLevel1Layer, RTSMapInitialization.StyleType.Satellite);
RTSMapInitialization.InitializeHwyShieldLevel1(highwayShieldLevel1Layer, RTSMapInitialization.StyleType.Satellite);
RTSMapInitialization.InitializeOuterZoomDetailLevel2(outerZoomLevel2Layer, RTSMapInitialization.StyleType.Satellite);
RTSMapInitialization.InitializeInnerZoomDetailLevel2(innerZoomLevel2Layer, RTSMapInitialization.StyleType.Satellite);
layers.Add(innerZoomLevel2Layer);
layers.Add(outerZoomLevel2Layer);
layers.Add(outerZoomLevel1Layer);
layers.Add(outerZoomLevel0Layer);
layers.Add(highwayShieldLevel1Layer);
layers.Add(highwayShieldLevel0Layer);
}
private void AddSatelliteLayers(GeoCollection<Layer> layers, RTSDataStore dataStore)
{
InMemoryFeatureLayer outerZoomLevel0Layer = new RTSFeatureLayer(FeatureType.Streets, “LEVEL0”, dataStore);
InMemoryFeatureLayer highwayShieldLevel0Layer = new RTSFeatureLayer(FeatureType.Streets, “LEVEL0”, dataStore);
InMemoryFeatureLayer outerZoomLevel1Layer = new RTSFeatureLayer(FeatureType.Streets, “LEVEL1”, dataStore);
InMemoryFeatureLayer highwayShieldLevel1Layer = new RTSFeatureLayer(FeatureType.Streets, “LEVEL1”, dataStore);
InMemoryFeatureLayer outerZoomLevel2Layer = new RTSFeatureLayer(FeatureType.Streets, “OUTERZOOMLEVEL2”, dataStore);
InMemoryFeatureLayer innerZoomLevel2Layer = new RTSFeatureLayer(FeatureType.Streets, “INNERZOOMLEVEL2”, dataStore);
InMemoryFeatureLayer innerZoomLevel3Layer = new RTSFeatureLayer(FeatureType.Streets, “INNERZOOMLEVEL3”, dataStore);
Proj4Projection proj4 = new Proj4Projection();
proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
innerZoomLevel2Layer.FeatureSource.Projection = proj4;
outerZoomLevel2Layer.FeatureSource.Projection = proj4;
outerZoomLevel1Layer.FeatureSource.Projection = proj4;
outerZoomLevel0Layer.FeatureSource.Projection = proj4;
highwayShieldLevel1Layer.FeatureSource.Projection = proj4;
highwayShieldLevel0Layer.FeatureSource.Projection = proj4;
RTSMapInitialization.InitializeDetailLevel0(outerZoomLevel0Layer, RTSMapInitialization.StyleType.Satellite);
RTSMapInitialization.InitializeHwyShieldLevel0(highwayShieldLevel0Layer, RTSMapInitialization.StyleType.Satellite);
RTSMapInitialization.InitializeDetailLevel1(outerZoomLevel1Layer, RTSMapInitialization.StyleType.Satellite);
RTSMapInitialization.InitializeHwyShieldLevel1(highwayShieldLevel1Layer, RTSMapInitialization.StyleType.Satellite);
RTSMapInitialization.InitializeOuterZoomDetailLevel2(outerZoomLevel2Layer, RTSMapInitialization.StyleType.Satellite);
RTSMapInitialization.InitializeInnerZoomDetailLevel2(innerZoomLevel2Layer, RTSMapInitialization.StyleType.Satellite);
layers.Add(innerZoomLevel2Layer);
layers.Add(outerZoomLevel2Layer);
layers.Add(outerZoomLevel1Layer);
layers.Add(outerZoomLevel0Layer);
layers.Add(highwayShieldLevel1Layer);
layers.Add(highwayShieldLevel0Layer);
}
private void SetDataStoreForAllLayers(RTSDataStore dataStore, GeoCollection<Layer> layers)
{
foreach (RTSFeatureLayer layer in layers)
{
((RTSFeatureSource)layer.RTSFeatureSource).DataStore = dataStore;
}
}
}
}