StationA / tilenol

Scalable, multi-backend geo vector tile server
MIT License
22 stars 6 forks source link

Cache-per-layer #45

Closed jerluc closed 3 years ago

jerluc commented 3 years ago

This changeset closes #25 by implementing a simple cache-per-layer approach (as opposed to the current approach of cache-per-URL). At a high level, this is how the new caching approach works:

With these changes in place, we get a few major improvements:

  1. Improved cache hit ratio for multi-layer configurations: because this now caches per layer vs. per URL/request, we should see moderate performance improvements for mixed-combination tile requests, e.g. a request to something like /_all/z/x/y.mvt, followed by /layer1/z/x/y.mvt, should hit the layer1 cache on the second request, since layer1 gets cached in the first request at a more granular cache key
  2. More fine-grained control for the caching behavior of multi-layer configurations: there's still room for improvement, but between computing hash keys per layer (vs. per URL), and exposing the optional nocache option for each configured layer, this adds an extra level of flexibility
  3. Better path forward for reconfigurations: previously there was some buggy cache behavior when reconfiguring a layer under the cache-per-URL implementation, as the URL doesn't change even if your layer configuration does; by using the configuration in the cache key (using the configuration hash digest), we can ensure that layer data is freshly retrieved whenever its configuration changes, and that layer cache data is reused when the configuration is the same
  4. Better resilience to cache failure: previously, if retrieving data from the cache failed for any reason, we would fail the entire request; in this revised implementation, cache retrieval failures are treated the same as a cache miss, which should fix a broad class of potential issues (e.g. temporary network failures, bad data/deserialization issues, etc.)

That said, there are a couple of potential new thoughts that come out of this: