chiitiler 1.24.3 → 1.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -192,19 +192,19 @@ retaining native renderer memory between requests.
192
192
 
193
193
  Chiitiler caches *source assets* (vector tiles, glyphs, sprites) — not final rasters — so cached data is reused across requests. Standard AWS / GCP credentials (`AWS_ACCESS_KEY_ID`, `GOOGLE_APPLICATION_CREDENTIALS`, etc.) are respected.
194
194
 
195
- The tile server adds a per-process memory front cache to `file`, `s3`, and `gcs`:
196
- by default, buffers are retained for 10 seconds from insertion, with an LRU limit of 64 MiB
197
- of buffer payloads (JavaScript overhead is additional). Reads promote backing-cache
198
- hits into memory; writes populate memory immediately and also write to the backing
199
- cache. `none` and `memory` keep their existing behavior. This affects sources that
200
- already use the cache, not direct `s3://`, `gs://`, or local source reads.
195
+ For the `file`, `s3` and `gcs` cache methods, the tile server adds a per-process memory front
196
+ cache (not for `none`, which declines caching, or `memory`, which is already in-process): by default, buffers are retained for 10 seconds from insertion, with an
197
+ LRU limit of 64 MiB of buffer payloads (JavaScript overhead is additional). It applies to
198
+ every source (`http(s)://`, `s3://`, `gs://`, `file://`, `mbtiles://`, `pmtiles://`, `cog://`).
199
+ Only `http(s)://` sources (including `pmtiles://http(s)://` tiles) are also stored in the
200
+ backing cache; reads promote backing-cache hits into memory, and writes populate memory
201
+ immediately and also write to the backing cache.
201
202
 
202
203
  Set `--front-cache-ttl-sec` / `CHIITILER_FRONT_CACHE_TTL_SEC` to a positive, finite number of seconds and
203
204
  `--front-cache-max-bytes` / `CHIITILER_FRONT_CACHE_MAX_BYTES` to a positive integer number of bytes to override
204
- these limits. CLI flags take precedence over environment variables. Setting either limit to `0` disables the front cache and uses the
205
- backing cache directly. Otherwise, invalid values stop startup when using `file`,
206
- `s3`, or `gcs`.
207
- These settings do not affect `none`, `memory`, or library callers.
205
+ these limits. CLI flags take precedence over environment variables. Set either limit to `0`
206
+ (e.g. `CHIITILER_FRONT_CACHE_TTL_SEC=0`) to disable the front cache entirely. Otherwise,
207
+ invalid values stop startup. These settings do not affect library callers.
208
208
 
209
209
  The front-cache TTL does not guarantee source freshness: promotion can retain a
210
210
  value for up to the configured TTL beyond its backing-cache expiry, and the S3/GCS cache
@@ -23,6 +23,13 @@ export function withMemoryCache(backing, { ttlSeconds = 10, maxBytes = 64 * 1024
23
23
  const reads = new Map();
24
24
  return {
25
25
  name: backing.name,
26
+ memory: {
27
+ name: 'memory',
28
+ get: async (key) => memory.get(key),
29
+ set: async (key, value) => {
30
+ memory.set(key, value);
31
+ },
32
+ },
26
33
  get: async (key) => {
27
34
  const hit = memory.get(key);
28
35
  if (hit !== undefined)
@@ -8,6 +8,8 @@ type Cache = {
8
8
  name: string;
9
9
  get: (key: string) => Promise<Value | undefined>;
10
10
  set: (key: string, value: Value) => Promise<void>;
11
+ /** Short-lived in-process layer (set by withMemoryCache), applied to every source. */
12
+ memory?: Cache;
11
13
  };
12
14
  declare const noneCache: () => Cache;
13
15
  export { noneCache, memoryCache, s3Cache, gcsCache, fileCache, type Value, type Cache };
package/dist/cli.js CHANGED
@@ -149,6 +149,7 @@ export function createProgram() {
149
149
  port: parsePort(options.port),
150
150
  debug: parseDebug(options.debug),
151
151
  };
152
+ // none: caching was declined; memory: already in-process
152
153
  if (['file', 's3', 'gcs'].includes(serverOptions.cache.name)) {
153
154
  const ttl = options.frontCacheTtlSec;
154
155
  const size = options.frontCacheMaxBytes;
@@ -3,7 +3,6 @@
3
3
  import { noneCache } from '../cache/index.js';
4
4
  import { getUserAgent } from './userAgent.js';
5
5
  async function getHttpSource(uri, cache = noneCache()) {
6
- // use cache only for http(s) sources
7
6
  const val = await cache.get(uri);
8
7
  if (val !== undefined)
9
8
  return val; // hit
@@ -4,7 +4,7 @@ import { Cache } from '../cache/index.js';
4
4
  * Concurrent requests for the same uri share a single in-flight fetch
5
5
  * (single-flight) to avoid duplicate downloads.
6
6
  * @param uri
7
- * @param cache {Cache} - Cache Strategy. Affect only for http(s) sources.
7
+ * @param cache {Cache} - Cache Strategy. Its memory layer applies to every source; the backing cache only to http(s).
8
8
  * @returns
9
9
  */
10
10
  declare function getSource(uri: string, cache?: Cache): Promise<Buffer | null>;
@@ -6,6 +6,20 @@ import { getS3Source } from './s3.js';
6
6
  import { getGCSSource } from './gcs.js';
7
7
  import { getCogSource } from './cog.js';
8
8
  import { noneCache } from '../cache/index.js';
9
+ /**
10
+ * Every source reads through the short-lived in-process memory layer.
11
+ * Only http(s) sources also persist to the backing cache (in fetchSource).
12
+ * Empty results are not cached.
13
+ */
14
+ async function cached(uri, { memory: cache = noneCache() }, load) {
15
+ const val = await cache.get(uri);
16
+ if (val !== undefined)
17
+ return val;
18
+ const buf = await load();
19
+ if (buf !== null && buf.length > 0)
20
+ cache.set(uri, buf);
21
+ return buf;
22
+ }
9
23
  async function fetchSource(uri, cache) {
10
24
  if (uri.startsWith('http://') || uri.startsWith('https://'))
11
25
  return getHttpSource(uri, cache);
@@ -29,14 +43,14 @@ const inFlight = new Map();
29
43
  * Concurrent requests for the same uri share a single in-flight fetch
30
44
  * (single-flight) to avoid duplicate downloads.
31
45
  * @param uri
32
- * @param cache {Cache} - Cache Strategy. Affect only for http(s) sources.
46
+ * @param cache {Cache} - Cache Strategy. Its memory layer applies to every source; the backing cache only to http(s).
33
47
  * @returns
34
48
  */
35
49
  async function getSource(uri, cache = noneCache()) {
36
50
  const existing = inFlight.get(uri);
37
51
  if (existing !== undefined)
38
52
  return existing;
39
- const promise = fetchSource(uri, cache).finally(() => {
53
+ const promise = cached(uri, cache, () => fetchSource(uri, cache)).finally(() => {
40
54
  inFlight.delete(uri);
41
55
  });
42
56
  inFlight.set(uri, promise);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "chiitiler",
4
- "version": "1.24.3",
4
+ "version": "1.25.1",
5
5
  "description": "Tiny map rendering server for MapLibre Style Spec",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",