Closed keitakn closed 1 year ago
APICacheの一例として参考になる記事。
https://javascript.plainenglish.io/how-to-cache-api-calls-in-next-js-f4b6aefa84f1
CloudFlare Workersを使って解決出来ないか?
APIへの直接リクエストをやめてCloudFlare Workersを使って作成したAPI Proxyを通すようにする。
その中でアクセストークンの発行などを行ってしまえばクライアント側から毎回アクセストークンの発行も不要になる。
D1を使えばアクセストークンのCacheも可能になる。
画像データをbase64で送るのでpayloadサイズの制限に引っかからないかが心配。要検証。
これもアリ、割と選択肢が多い事に気がつく。
https://zenn.dev/tkithrta/articles/a56603a37b08f0
VercelのEdge API Routesでのサンプルも載っている。
VercelのEdge Runtime 、CloudFlare Workersだとアカウントを新規で作成しないといけないが、Vercelを使う場合はそれをしなくて良いのがメリットにはなりそう。
Vercelを使う場合は以下を参考に技術検証をしてみる。
https://vercel.com/docs/concepts/functions/edge-functions/quickstart
Doneの定義
有効期限内はCacheに保存されているトークンを再利用するようになっている事
補足情報
クライアントサイドへのCacheはセキュリティ的にNG。
何とかしてサーバー側にCacheさせる方法を考える。