tilestrata-lru
v0.2.0
Published
A TileStrata plugin for caching tiles in memory
Downloads
49
Maintainers
Readme
tilestrata-lru
A basic TileStrata plugin for caching tiles to memory. Use cautiously – out of memory crashes are entirely possible if not configured carefully. If you want to share a single LRU across multiple layers and routes, that's just fine (the cache keys account for that).
$ npm install tilestrata-lru --save
Sample Usage
var lru = require('tilestrata-lru');
// set total size limit of cache
server.layer('mylayer').route('tile.pbf')
.use(/* some provider */)
.use(lru({size: '20mb', ttl: 30})); // ttl in seconds
// or set a total number of items
server.layer('mylayer').route('tile.pbf')
.use(/* some provider */)
.use(lru({size: 20, ttl: 30}));
// set a function for the cache key
server.layer('mylayer').route('tile.pbf')
.use(/* some provider */)
.use(lru({key: function(req) {
var compressed = /gzip|deflate/.test(req.headers['accept-encoding']) ? 1 : 0;
return req.z+','+req.x+','+req.y+','+req.layer+','+req.filename+','+compressed;
}}));
Contributing
Before submitting pull requests, please update the tests and make sure they all pass.
$ npm test
License
Copyright © 2015–2016 Natural Atlas, Inc. & Contributors
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.