ThinkGeo.com    |     Documentation    |     Premium Support

ServerCache questions and possibly issues

Hi ThinkGeo Forum,

We are working on implementing the servercache for our web project to improve performance. One observation we had was it appears that every time we load the project it appears to take the same amount of time as initially building the tiles. We have verified the files are created in the correct location and that they are not overwritten after being created. We have also observed this both with the debugger attached and without it attached. Is there something we are missing?

objLayersOverlay.ServerCache.CacheDirectory = Path.GetDirectoryName(@“C:\GIS”);
objLayersOverlay.ServerCache.CacheId = “Cache”;

In addition to this, we were wanted to generate several zoom levels of the tiles initially. We were doing it it this way.
objLayerOverlay.GenerateCacheImages(Map1.ZoomLevelSet.ZoomLevel12, objLayerOverlay.GetBoundingBox(), objMapUnits);

The two issues we noticed and the first observation we wrote about above where it seems to attempt to rebuild the tiles. The second is that the tiles did not align with bing maps nor any new tiles created that were not within the extent (they lined up when the tiles are are automatically created NOT using GenerateCacheImages). A lot of our clients use the various California State Plane projections. Would projections play an issue with the tiles not aligning correctly? Could it be because they are off as well that it’s attempting to draw more?

Any help would greatly be appreciated.

Thank you,

Neil

Hi Neil,

I suggest you modify cached tile, for example add a water maker at first, then run the application again to see whether the map really load the cached ones, then we can know whether the problem is related with cache.

Could you please let us know how you think the tiles will be rebuild when it loaded after you call GenerateCacheImages?

If you want to pre-build cache, you can also try our utility https://github.com/ThinkGeo/CacheGeneratorSample-ForWinForms.

Regards,

Ethan

Hi Ethan,

I tested out the water mark on the server files and loading the map showed the edited png file. The one thing I noticed is when I load the project it appears to behave as if it’s performing clientcache though we have verified that functionality is not implemented. It is as if the server cache is being loaded to the client. In Developer Tools on chrome we observed all the tiles loading on the client https://www.screencast.com/t/pCWxpEZQPri. Additionally, our diagnostics tools in Visual Studio are showing the tile_GeoResource.axd event occurring https://www.screencast.com/t/pHHcShe7uQx2 each time the project loads or we zoom/pan around. Once the tiles been loaded this event does not occur. Is this the expected behavior of ServerCache on web edition?

As for GenerateCacheImages, we were hoping to create the tiles dynamically and then be able to load in those tiles in when the map loads. Currently our issue with it is that it’s creating the tiles off center by a considerable distance. That utility on github sadly will not meet our needs as we have many clients and do not want to manually go through each clients shapefiles to generate their tiles.

Appreciate the help!

Thank you,
Neil

Hi Neil,

If you think the client cache is the distractors I think you can close it or set the expired time a very short seconds. The server cache means the cache is from server side, so each time you pan or zoom it still need to require image from server side, the different is it’s faster than dynamic render data in server side.

And if the only choice is GenerateCacheImages please show us a simple sample, so we can see whether we can help you on it.

Regards,

Ethan

Hi Ethan,

Sadly I do not know how to close the client cache, do you know how that can be done? We tried the short expiring time and that just made it where the client cache had to be drawn again regularly. Needless to say, we do NOT want ClientCache. We have commented out the code for it and are NOT using the .ClientCache off of the LayerOverlay and we are using the .ServerCache only. What we have observed is that it appears that ClientCache still runs even with it not being used in our code. So my question is this, when using ServerCache, does it load the tiles from the server side and then loads/draws those tiles to the client?

From my observation it looks like Clientcache is still loading when only ServerCache is being used. This drawing process slows down the loading of the tiles, which are coming from the server. Here is a video showing the Diagnostic tools and our project loading the tiles https://www.screencast.com/t/xQR5s6ubUv5L. For reference, the server tiles are being loaded in since we put a “Test” on a few of the tiles server side. We have also made sure to clear out our Cache for the browser. Once the tiles are loaded for that zoom level returning to that zoom level the tiles load in fast similar to how ClientCache works https://www.screencast.com/t/qKNJConGZys.

Additional items of this observation.

When we have Client Cache on and we have the CacheID set to “TestingClientCache”, the tile’s src is
“tile_GeoResource.axd?BBOX=-13564189.111365,4516521.2348118,-13544621.243025,4536089.1031518&CACHEID=TestingClientCache&CLIENTID=MainContent_Map1&EXTRA=27090835835&FORMAT=image%2Fpng&HEIGHT=256&OId=8101d571-02c6-4fba-8858-de2c023af16d&OVERLAYID=8101d571-02c6-4fba-8858-de2c023af16d&PAGENAME=qTSWy3ACvEmrGH5dI19OQ&SRS=EPSG%3A900913&STYLES=&WIDTH=256&ZOOM=11”

While when we do not have Client Cache on the tile’s src is
“tile_GeoResource.axd?BBOX=-13564189.111365,4516521.2348118,-13544621.243025,4536089.1031518&CACHEID=&CLIENTID=MainContent_Map1&EXTRA=270923462346&FORMAT=image%2Fpng&HEIGHT=256&OId=756c127c-a923-4bd2-8466-ee3ce5e0c987&OVERLAYID=756c127c-a923-4bd2-8466-ee3ce5e0c987&PAGENAME=RthnDGC2NUSF32gqn4NXyA&SRS=EPSG%3A900913&STYLES=&WIDTH=256&ZOOM=11”

They look rather identical outside the CACHEID.

As for the GenerateCacheImages, this process still has the same issues that I listed out above for ServerCache with the additional issue of drawing the tiles off center of where they are suppose to be. I will attempt to create a sample project for GenerateCacheImages for the off center issue.

Thank you for your help.

Neil

Hi Neil,

If you set short expiring time don’t work, please try to set ClientCache = null and see whether it can close the ClientCache, I think if you just comment it, the client cache still works.

About your question, “when using ServerCache, does it load the tiles from the server side and then loads/draws those tiles to the client”, the answer is when you use ServerCache, client side still need to load tiles from server side.

If you complete the sample please let us know.

Regards,

Ethan

Hi Ethan,

We attempted setting the Client Cache to null and it is not possible to set it to null. Also thank you for the clarification on the ServerCache.

I completed a test project to show the issue with GenerateCacheImages. I created a sample Shapefile that matched the project of our clients shapefiles. Here are some images below showing the issue.

When the ServerCache is built by GenerateCacheImages:
https://www.screencast.com/t/zcEx5mkbhhE
https://www.screencast.com/t/FoEJBd7oX8m
https://www.screencast.com/t/aEEN4f67vr

When the ServerCache is built on the fly without GenerateCacheImages:
https://www.screencast.com/t/8y97BPr8
https://www.screencast.com/t/9DRdy0hIyCGr
https://www.screencast.com/t/XTaucm5qimN

Here is the code:

WebForm1.aspx.cs

using System;
using System.Web.UI;
using System.IO;
using ThinkGeo.MapSuite.WebForms;
using ThinkGeo.MapSuite.Drawing;
using ThinkGeo.MapSuite.Layers;
using ThinkGeo.MapSuite.Shapes;
using ThinkGeo.MapSuite.Styles;
using ThinkGeo.MapSuite;

namespace Test
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string strFile = @“C:\GIS”; //Local File Path for testing
try
{
if (!Page.IsPostBack)
{
Map1.MapBackground = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
string applicationID = “Your Key Here”;

                BingMapsOverlay mobjBingsOverlay = new BingMapsOverlay("ROADS", applicationID);
                mobjBingsOverlay.MapStyle = BingMapsStyle.Road;
                mobjBingsOverlay.Name = "Roads";
                Map1.CustomOverlays.Add(mobjBingsOverlay);
                Map1.MapUnit = GeographyUnit.Meter;
                ShapeFileFeatureLayer objLayer = new ShapeFileFeatureLayer(strFile + "TestShape.shp");
                //Set's the Style
                objLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
                objLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
                //Works with the projection
                Proj4Projection objProjectionJUR = new Proj4Projection();
                string strProjection = null;
                string strFileFull = strFile + "TestShape.shp";
                ShapeFileFeatureLayer.BuildIndexFile(strFileFull); 
                strProjection = File.ReadAllText(strFileFull.Replace(".shp", ".prj")); //Obtains all prj files matching the reference. 
                                                                                       //strProjection = ReadAllText(strFile.Replace(".shp", ".prj")); //Obtains all prj files matching the reference. 
                objProjectionJUR.InternalProjectionParametersString = Proj4Projection.ConvertPrjToProj4(strProjection);
                objProjectionJUR.ExternalProjectionParametersString = Proj4Projection.GetBingMapParametersString();
                objProjectionJUR.Open();
                objLayer.FeatureSource.Projection = objProjectionJUR;
                LayerOverlay objOverlay = new LayerOverlay();
                objOverlay.Layers.Add("Test", objLayer);
                Map1.CustomOverlays.Add(objOverlay);
                objLayer.Open(); 
                Map1.CurrentExtent = objLayer.GetBoundingBox();
                objOverlay.ServerCache.CacheDirectory = Path.GetDirectoryName(strFile);
                objOverlay.ServerCache.CacheId = "Main";
                //Comment out GenerateCacheImages and remove the cached folder to test ServerCaching loading on the fly. 
                objOverlay.GenerateCacheImages(Map1.ZoomLevelSet.ZoomLevel10, objOverlay.GetBoundingBox(), Map1.MapUnit);
                objOverlay.GenerateCacheImages(Map1.ZoomLevelSet.ZoomLevel11, objOverlay.GetBoundingBox(), Map1.MapUnit);
                objOverlay.GenerateCacheImages(Map1.ZoomLevelSet.ZoomLevel12, objOverlay.GetBoundingBox(), Map1.MapUnit);
                objOverlay.GenerateCacheImages(Map1.ZoomLevelSet.ZoomLevel13, objOverlay.GetBoundingBox(), Map1.MapUnit);
                objOverlay.GenerateCacheImages(Map1.ZoomLevelSet.ZoomLevel14, objOverlay.GetBoundingBox(), Map1.MapUnit);
                objOverlay.GenerateCacheImages(Map1.ZoomLevelSet.ZoomLevel15, objOverlay.GetBoundingBox(), Map1.MapUnit);
                objOverlay.GenerateCacheImages(Map1.ZoomLevelSet.ZoomLevel16, objOverlay.GetBoundingBox(), Map1.MapUnit);
                objOverlay.GenerateCacheImages(Map1.ZoomLevelSet.ZoomLevel17, objOverlay.GetBoundingBox(), Map1.MapUnit);
                objOverlay.GenerateCacheImages(Map1.ZoomLevelSet.ZoomLevel18, objOverlay.GetBoundingBox(), Map1.MapUnit);
            }
        }
        catch (Exception ex)
        {
            lblSuccess.Text = ex.Message;
        }
    }
}

}

WebForm1.aspx

> <%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Test.WebForm1" %>

> <%@ Register Assembly="ThinkGeo.MapSuite.WebForms" Namespace="ThinkGeo.MapSuite.WebForms" TagPrefix="cc1" %>

> <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
>     <script type="text/javascript">
>         var OnMapCreating = function (map) {

>         }

>     </script>    

>     <div>
>         <asp:Label ID="lblExists" runat="server"></asp:Label>
>         <asp:Label ID="lblSuccess" runat="server"></asp:Label>
>         <cc1:Map ID="Map1" runat="server" Height="600px" Width="800px"></cc1:Map>
>     </div>

> <%--    <asp:Button ID="Button" runat="server" OnClick="Button_Click" Text="Add Layer"/>--%>

> </asp:Content>

Thank you,

Neil TestShape.zip (2.3 KB)

Hi Ethan,

Also, we tested the ServerCache on the server and the performance is greatly enhanced. There just may be something about testing it locally that uses more resources even without using the Debugger. Either way, hope this helps someone in the future.

So hopefully we can figure out the GenerateCacheImages and we will greatly appreciate it.

Thanks,
Neil

Hi Neil,

Thanks for your data and code, we reproduce it, that’s strange because it looks the generate logic is just the same like what it did by map auto generate cache.

Our developer will keep look into it and upgrade the status if we get any good news.

And in fact the “GenerateCacheImages” API takes the same long time as the map generate the cache tile, so you can just set the ServerCache and don’t call “GenerateCacheImages”, the cache image will be generated when the extent accessed by any user the first time.

Regards,

Ethan

Hi Ethan,

Sounds good, thank you for all the assistance. We will be hoping your developers will be able to fix it as it does take a decent amount of time to generate the cache images when first accessed. Either way, we will consider our options and go from there.

Thank you once again for the help,

Neil

Hi Neil,

Our developer will works for it, and update the status in the ticket.

Regards,

Ethan