@xiboplayer/cache 0.1.3 → 0.3.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 +50 -0
- package/package.json +2 -2
- package/src/cache-proxy.js +12 -17
- package/src/cache.test.js +12 -2
- package/src/download-manager.js +767 -303
- package/src/download-manager.test.js +1130 -325
- package/src/index.js +3 -1
- package/docs/README.md +0 -118
package/src/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// @xiboplayer/cache - Offline caching and downloads
|
|
2
|
+
import pkg from '../package.json' with { type: 'json' };
|
|
3
|
+
export const VERSION = pkg.version;
|
|
2
4
|
export { CacheManager, cacheManager } from './cache.js';
|
|
3
5
|
export { CacheProxy } from './cache-proxy.js';
|
|
4
|
-
export { DownloadManager } from './download-manager.js';
|
|
6
|
+
export { DownloadManager, FileDownload, LayoutTaskBuilder, isUrlExpired } from './download-manager.js';
|
package/docs/README.md
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
# @xiboplayer/cache Documentation
|
|
2
|
-
|
|
3
|
-
**Offline caching and download management with parallel chunk downloads.**
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
The `@xiboplayer/cache` package provides:
|
|
8
|
-
|
|
9
|
-
- **CacheManager** - IndexedDB-based media storage
|
|
10
|
-
- **CacheProxy** - Service Worker integration
|
|
11
|
-
- **DownloadManager** - Parallel chunk downloads (4x faster)
|
|
12
|
-
|
|
13
|
-
## Installation
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm install @xiboplayer/cache
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Usage
|
|
20
|
-
|
|
21
|
-
```javascript
|
|
22
|
-
import { CacheManager, DownloadManager } from '@xiboplayer/cache';
|
|
23
|
-
|
|
24
|
-
// Initialize cache
|
|
25
|
-
const cache = new CacheManager();
|
|
26
|
-
await cache.initialize();
|
|
27
|
-
|
|
28
|
-
// Download with parallel chunks
|
|
29
|
-
const downloader = new DownloadManager(cache);
|
|
30
|
-
await downloader.downloadFile(url, { chunkSize: 1024 * 1024 });
|
|
31
|
-
|
|
32
|
-
// Retrieve from cache
|
|
33
|
-
const blob = await cache.get(url);
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Features
|
|
37
|
-
|
|
38
|
-
### Parallel Chunk Downloads
|
|
39
|
-
|
|
40
|
-
Downloads large files in 4 concurrent chunks (configurable), achieving 2-4x speed improvement over sequential downloads.
|
|
41
|
-
|
|
42
|
-
```javascript
|
|
43
|
-
const CONCURRENT_CHUNKS = 4; // Adjust 2-6 based on network
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### Cache Validation
|
|
47
|
-
|
|
48
|
-
Automatically validates cached entries:
|
|
49
|
-
- Content-Type verification
|
|
50
|
-
- Size validation (> 100 bytes)
|
|
51
|
-
- Corrupted entry detection
|
|
52
|
-
|
|
53
|
-
### Blob URL Lifecycle
|
|
54
|
-
|
|
55
|
-
Proper blob URL management prevents memory leaks:
|
|
56
|
-
- Layout-scoped tracking
|
|
57
|
-
- Automatic revocation on layout switch
|
|
58
|
-
- Media URL cleanup
|
|
59
|
-
|
|
60
|
-
## API Reference
|
|
61
|
-
|
|
62
|
-
### CacheManager
|
|
63
|
-
|
|
64
|
-
```javascript
|
|
65
|
-
class CacheManager {
|
|
66
|
-
async initialize()
|
|
67
|
-
async get(key)
|
|
68
|
-
async set(key, blob)
|
|
69
|
-
async has(key)
|
|
70
|
-
async delete(key)
|
|
71
|
-
async clear()
|
|
72
|
-
async getSize()
|
|
73
|
-
}
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
### DownloadManager
|
|
77
|
-
|
|
78
|
-
```javascript
|
|
79
|
-
class DownloadManager {
|
|
80
|
-
constructor(cacheManager, options)
|
|
81
|
-
async downloadFile(url, options)
|
|
82
|
-
async downloadBatch(urls)
|
|
83
|
-
getProgress(url)
|
|
84
|
-
}
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### CacheProxy
|
|
88
|
-
|
|
89
|
-
```javascript
|
|
90
|
-
class CacheProxy {
|
|
91
|
-
constructor(cacheManager)
|
|
92
|
-
register(serviceWorkerUrl)
|
|
93
|
-
unregister()
|
|
94
|
-
update()
|
|
95
|
-
}
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
## Performance
|
|
99
|
-
|
|
100
|
-
| Operation | Time |
|
|
101
|
-
|-----------|------|
|
|
102
|
-
| 1GB file download | 1-2 min (vs 5 min sequential) |
|
|
103
|
-
| Cache lookup | <10ms |
|
|
104
|
-
| Cache write | <50ms |
|
|
105
|
-
|
|
106
|
-
## Dependencies
|
|
107
|
-
|
|
108
|
-
- `@xiboplayer/utils` - Logger, EventEmitter
|
|
109
|
-
|
|
110
|
-
## Related Packages
|
|
111
|
-
|
|
112
|
-
- [@xiboplayer/core](../../core/docs/) - Player core
|
|
113
|
-
- [@xiboplayer/sw](../../sw/docs/) - Service Worker toolkit
|
|
114
|
-
|
|
115
|
-
---
|
|
116
|
-
|
|
117
|
-
**Package Version**: 1.0.0
|
|
118
|
-
**Last Updated**: 2026-02-10
|