feat: add cache support
Adds support for a local cache of source images. I can add tests and docs if you're happy with the approach. It uses unstorage to store metadata on the cached files (etag, lastModified) and murmurhash to create filenames based on the URL.
Let me know if this seems like a good apporach and I'll finish off the PR!
Fixes #46
Codecov Report
Merging #47 (e63c14f) into main (eafe4ca) will decrease coverage by
2.14%. The diff coverage is22.22%.
@@ Coverage Diff @@
## main #47 +/- ##
==========================================
- Coverage 45.60% 43.46% -2.15%
==========================================
Files 10 10
Lines 296 329 +33
Branches 54 66 +12
==========================================
+ Hits 135 143 +8
- Misses 159 184 +25
Partials 2 2
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/sources/http.ts | 28.57% <18.18%> (-7.80%) |
:arrow_down: |
| src/ipx.ts | 77.41% <66.66%> (-0.55%) |
:arrow_down: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update eafe4ca...e63c14f. Read the comment docs.
Thanks for PR @ascorbic. It is a nice start. BTW to points:
- Reason for having unstorage, is to keep it abstract to end-users. By directly importing a Node.js-only driver (
fs), we are essentially making library Node.js dependant. We shall simply use a default instance and let users provide other storage drivers like S3 or FS - Storage instance can be created directly in
ipx.tsso that we can leverage it to cache transform result in the future and at one point unify sources in favor of unstorage drivers (#30) - There is a WIP library for caching support on top of unstorage but in the meantime would not harm to have basic cache for HTTP only :)
Hi dear @ascorbic thanks again for initiative work on this ❤️ I plan to rework this with new storage implementation for IPX 0.2.x. Closing PR for triage.