chiitiler 1.24.3 → 1.25.0
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 +10 -10
- package/dist/cache/front.js +7 -0
- package/dist/cache/index.d.ts +2 -0
- package/dist/cli.js +6 -8
- package/dist/source/http.js +0 -1
- package/dist/source/index.d.ts +1 -1
- package/dist/source/index.js +16 -2
- package/package.json +1 -1
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
|
|
196
|
-
by default, buffers are retained for 10 seconds from insertion, with an
|
|
197
|
-
of buffer payloads (JavaScript overhead is additional).
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
195
|
+
The tile server adds a per-process memory front cache to every cache method, including
|
|
196
|
+
`none` and `memory`: 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.
|
|
205
|
-
|
|
206
|
-
|
|
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
|
package/dist/cache/front.js
CHANGED
|
@@ -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)
|
package/dist/cache/index.d.ts
CHANGED
|
@@ -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,14 +149,12 @@ export function createProgram() {
|
|
|
149
149
|
port: parsePort(options.port),
|
|
150
150
|
debug: parseDebug(options.debug),
|
|
151
151
|
};
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
});
|
|
159
|
-
}
|
|
152
|
+
const ttl = options.frontCacheTtlSec;
|
|
153
|
+
const size = options.frontCacheMaxBytes;
|
|
154
|
+
serverOptions.cache = caches.withMemoryCache(serverOptions.cache, {
|
|
155
|
+
ttlSeconds: ttl === undefined ? undefined : Number(ttl.trim() || NaN),
|
|
156
|
+
maxBytes: size === undefined ? undefined : Number(size.trim() || NaN),
|
|
157
|
+
});
|
|
160
158
|
if (serverOptions.debug) {
|
|
161
159
|
console.log(`running server: http://localhost:${serverOptions.port}`);
|
|
162
160
|
console.log(`cache method: ${serverOptions.cache.name}`);
|
package/dist/source/http.js
CHANGED
|
@@ -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
|
package/dist/source/index.d.ts
CHANGED
|
@@ -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.
|
|
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>;
|
package/dist/source/index.js
CHANGED
|
@@ -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.
|
|
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);
|