cachel 1.1.0 → 1.1.2
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 +7 -2
- package/cachel.js +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@ Offline-first asset caching for the browser, powered by IndexedDB.
|
|
|
5
5
|
Fetch remote assets once, serve them forever from local cache. Works with any framework or none at all.
|
|
6
6
|
|
|
7
7
|

|
|
8
|
+

|
|
8
9
|

|
|
9
10
|
|
|
10
11
|
---
|
|
@@ -15,7 +16,9 @@ Fetch remote assets once, serve them forever from local cache. Works with any fr
|
|
|
15
16
|
- Batch cache multiple assets with controlled concurrency via `loadMany`
|
|
16
17
|
- Serve cached assets as object URLs, works fully offline
|
|
17
18
|
- Skips network requests for already cached assets
|
|
19
|
+
- Singleton per database name
|
|
18
20
|
- Supports images, videos, audio and fonts
|
|
21
|
+
- Failed assets in batch processing are bypassed, successful ones are always cached
|
|
19
22
|
- No service worker required
|
|
20
23
|
- Zero dependencies
|
|
21
24
|
|
|
@@ -52,6 +55,8 @@ img.src = url; // works offline
|
|
|
52
55
|
|
|
53
56
|
Creates a new cachel instance. `name` is used as the IndexedDB database name, prefixed internally as `cachel:<name>`.
|
|
54
57
|
|
|
58
|
+
Multiple calls with the same name return the same instance, no duplicate IndexedDB connections.
|
|
59
|
+
|
|
55
60
|
```javascript
|
|
56
61
|
const cache = new Cachel('my-app'); // opens "cachel:my-app" in IndexedDB
|
|
57
62
|
```
|
|
@@ -70,7 +75,7 @@ await cache.load('https://example.com/hero.jpg');
|
|
|
70
75
|
|
|
71
76
|
Supported content types: `image/*`, `video/*`, `audio/*`, `font/*`
|
|
72
77
|
|
|
73
|
-
Throws if the
|
|
78
|
+
Throws if the resource cannot be fetched or the content type is not supported.
|
|
74
79
|
|
|
75
80
|
---
|
|
76
81
|
|
|
@@ -94,7 +99,7 @@ console.log(status);
|
|
|
94
99
|
// }
|
|
95
100
|
```
|
|
96
101
|
|
|
97
|
-
`chunkSize` controls how many assets are fetched in parallel per round. Defaults to `8`,
|
|
102
|
+
`chunkSize` controls how many assets are fetched in parallel per round. Defaults to `8`, clamped to a maximum of `8`. Assets already cached are skipped automatically.
|
|
98
103
|
|
|
99
104
|
```javascript
|
|
100
105
|
await cache.loadMany(urls, 4); // 4 parallel fetches per round
|
package/cachel.js
CHANGED
|
@@ -3,11 +3,14 @@ import { convertToBlob, chunkify } from './utils/index.js';
|
|
|
3
3
|
|
|
4
4
|
class Cachel {
|
|
5
5
|
|
|
6
|
+
static #instances = {};
|
|
6
7
|
#idb;
|
|
7
8
|
#defaultChunkSize = 8;
|
|
8
9
|
|
|
9
10
|
constructor(name = 'idb'){
|
|
11
|
+
if(Cachel.#instances[name]) return Cachel.#instances[name];
|
|
10
12
|
this.#idb = new Idb(name);
|
|
13
|
+
Cachel.#instances[name] = this;
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
async load(url){
|