ipx icon indicating copy to clipboard operation
ipx copied to clipboard

feat: add cache support

Open ascorbic opened this issue 4 years ago • 2 comments

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

ascorbic avatar Sep 20 '21 11:09 ascorbic

Codecov Report

Merging #47 (e63c14f) into main (eafe4ca) will decrease coverage by 2.14%. The diff coverage is 22.22%.

Impacted file tree graph

@@            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 data Powered by Codecov. Last update eafe4ca...e63c14f. Read the comment docs.

codecov-commenter avatar Sep 20 '21 11:09 codecov-commenter

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.ts so 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 :)

pi0 avatar Sep 20 '21 11:09 pi0

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.

pi0 avatar Oct 18 '23 01:10 pi0