Merge pull request #151 from twpayne/tile-cache-expiry

Tile cache expiry
This commit is contained in:
Tom Payne
2013-01-24 07:24:33 -08:00
8 changed files with 137 additions and 14 deletions

View File

@@ -2,6 +2,7 @@ goog.provide('ol.source.DebugTileSource');
goog.require('ol.Size');
goog.require('ol.Tile');
goog.require('ol.TileCache');
goog.require('ol.TileCoord');
goog.require('ol.source.TileSource');
goog.require('ol.tilegrid.TileGrid');
@@ -94,26 +95,40 @@ ol.source.DebugTileSource = function(options) {
/**
* @private
* @type {Object.<string, ol.DebugTile_>}
* FIXME will need to expire elements from this cache
* FIXME see elemoine's work with goog.structs.LinkedMap
* @type {ol.TileCache}
*/
this.tileCache_ = {};
this.tileCache_ = new ol.TileCache();
};
goog.inherits(ol.source.DebugTileSource, ol.source.TileSource);
/**
* @inheritDoc
*/
ol.source.DebugTileSource.prototype.canExpireCache = function() {
return this.tileCache_.canExpireCache();
};
/**
* @inheritDoc
*/
ol.source.DebugTileSource.prototype.expireCache = function(usedTiles) {
this.tileCache_.expireCache(usedTiles);
};
/**
* @inheritDoc
*/
ol.source.DebugTileSource.prototype.getTile = function(tileCoord) {
var key = tileCoord.toString();
if (goog.object.containsKey(this.tileCache_, key)) {
return this.tileCache_[key];
if (this.tileCache_.containsKey(key)) {
return /** @type {ol.DebugTile_} */ (this.tileCache_.get(key));
} else {
var tile = new ol.DebugTile_(tileCoord, this.tileGrid);
this.tileCache_[key] = tile;
this.tileCache_.set(key, tile);
return tile;
}
};

View File

@@ -5,6 +5,7 @@ goog.require('ol.Attribution');
goog.require('ol.Extent');
goog.require('ol.ImageTile');
goog.require('ol.Projection');
goog.require('ol.TileCache');
goog.require('ol.TileCoord');
goog.require('ol.TileUrlFunction');
goog.require('ol.TileUrlFunctionType');
@@ -55,32 +56,46 @@ ol.source.ImageTileSource = function(options) {
/**
* @private
* @type {Object.<string, ol.ImageTile>}
* FIXME will need to expire elements from this cache
* FIXME see elemoine's work with goog.structs.LinkedMap
* @type {ol.TileCache}
*/
this.tileCache_ = {};
this.tileCache_ = new ol.TileCache();
};
goog.inherits(ol.source.ImageTileSource, ol.source.TileSource);
/**
* @inheritDoc
*/
ol.source.ImageTileSource.prototype.canExpireCache = function() {
return this.tileCache_.canExpireCache();
};
/**
* @inheritDoc
*/
ol.source.ImageTileSource.prototype.expireCache = function(usedTiles) {
this.tileCache_.expireCache(usedTiles);
};
/**
* @inheritDoc
*/
ol.source.ImageTileSource.prototype.getTile = function(tileCoord) {
var key = tileCoord.toString();
if (goog.object.containsKey(this.tileCache_, key)) {
return this.tileCache_[key];
if (this.tileCache_.containsKey(key)) {
return /** @type {ol.Tile} */ (this.tileCache_.get(key));
} else {
var tileUrl = this.getTileCoordUrl(tileCoord);
var tile;
if (goog.isDef(tileUrl)) {
tile = new ol.ImageTile(tileCoord, tileUrl, this.crossOrigin_);
this.tileCache_.set(key, tile);
} else {
tile = null;
}
this.tileCache_[key] = tile;
return tile;
}
};

View File

@@ -1,6 +1,7 @@
goog.provide('ol.source.TileSource');
goog.provide('ol.source.TileSourceOptions');
goog.require('goog.functions');
goog.require('ol.Attribution');
goog.require('ol.Extent');
goog.require('ol.Projection');
@@ -46,6 +47,18 @@ ol.source.TileSource = function(tileSourceOptions) {
goog.inherits(ol.source.TileSource, ol.source.Source);
/**
* @return {boolean} Can expire cache.
*/
ol.source.TileSource.prototype.canExpireCache = goog.functions.FALSE;
/**
* @param {Object.<string, ol.TileRange>} usedTiles Used tiles.
*/
ol.source.TileSource.prototype.expireCache = goog.abstractMethod;
/**
* @inheritDoc
*/