如何为数据库驱动的Map-Tile Server实现缓存?

时间:2016-06-24 11:53:55

标签: asp.net caching leaflet

我们如何实现数据库驱动的Map-Tile Server的缓存?

我的想法是:

1)缓存内存中唯一z-x-y请求的响应(字节)(如果我们有一个大的地图区域,这将无法很好地扩展)

2a)随后将请求的图块呈现为文件系统/site/tiles/z/x/y.png和服务器

2b)应用合适的caching headers以确保HTTP 304重新请求

我已使用Leaflet.js和简单的 .aspx页面 实现了这个基本的地图图块服务器 - 请参阅here

每个map-tile请求都会命中db,拉出二进制tile-image并返回.png文件,如下所示:

MapTest.html

<div id='map'></div>

<script>
var map = L.map('map').setView([8.2, 6.95], 7);

L.tileLayer('**http://localhost/tileserver/tile.aspx?z={z}&x={x}&y={y}**', {
    minZoom: 7, maxZoom: 16,
    attribution: 'My Tile Server'
}).addTo(map);
</script>

Tiles.aspx

Option Strict On

Partial Class tile
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim z, x, y As Integer

        z = CInt(Request.QueryString("z"))
        x = CInt(Request.QueryString("x"))
        y = CInt(Request.QueryString("y"))

        Dim b() As Byte = DB.GetTile(z, x, y)

        Response.Buffer = True
        Response.Charset = ""
        'Response.Cache.SetCacheability(HttpCacheability.NoCache)
        Response.ContentType = "image/png"
        Response.AddHeader("content-disposition", "attachment;filename=" & y & ".png")
        Response.BinaryWrite(b)
        Response.Flush()
        Response.End()
    End Sub

请问如何通过有效的缓存来改善这一点?

0 个答案:

没有答案