sindresorhus / alfy

Create Alfred workflows with ease
MIT License
2.62k stars 104 forks source link

Question about caching, fetch vs alfy.fetch #174

Open kalaschnik opened 9 months ago

kalaschnik commented 9 months ago

Hey! I am writing my first Alfred workflow, and I have a general question about caching;

(1) How do I see if something I fetched gets cached? (2) Where is it stored? (3) Does my second execution and all subsequent executions of alfy.fetch use the cache? (3a) How can I very that? (4) The main difference between alfy.fetch and native fetch is that alfy.fetch does caching + json parse?

LitoMore commented 7 months ago
  1. How do I see if something I fetched gets cached?

You can't see the cached status. Code is here:

https://github.com/sindresorhus/alfy/blob/3d277f86ff366225e10ca8483bffee16e4f630e1/index.js#L115-L173

  1. Where is it stored?

The Alfred workflow_cache. See https://www.alfredapp.com/help/workflows/script-environment-variables/.

  1. Does my second execution and all subsequent executions of alfy.fetch use the cache?

The cache max-age is 5000 ms. You can catch the HTTP traffic to see if there are any requests.

  1. The main difference between alfy.fetch and native fetch is that alfy.fetch does caching + json parse?

Alfy is using https://github.com/sindresorhus/got. And we implemented the cache logic by ourself inside Alfy. You can check our source code.