unjs / unjs/ofetch

feat: support a way to override fetching behavior

Open
#108 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
5.4k
Forks
195
PR merge metrics
No merged PRs in 30d

Description

What's the best way to cache responses with ohmyfetch via an LRU cache?

With axios, I've used axios-extensions's "cacheAdapterEnhancer" like so:

import { cacheAdapterEnhancer } from 'axios-extensions';
import LRU from 'lru-cache';
const ONE_HOUR = 1000 * 60 * 60;
const defaultCache = new LRU({ maxAge: ONE_HOUR });
const defaults = $axios.defaults;
defaults.adapter = cacheAdapterEnhancer(defaults.adapter, {
  enabledByDefault: false,
  cacheFlag: 'useCache',
  defaultCache,
});

which caches responses when I explicitly add useCache: true to the request.

Is there a similar enhancer for ohmyfetch, or one planned, or an example of how to implement caching with ohmyfetch?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no specific file or test. Start by locating ofetch's request entry point and existing request-option documentation, then determine whether the intended result is a supported caching override or an implementation example; done should be a documented, testable resolution to that choice.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.