Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rehydrate the cache #9

Closed
francoischalifour opened this issue Aug 15, 2019 · 1 comment · Fixed by #15
Closed

Rehydrate the cache #9

francoischalifour opened this issue Aug 15, 2019 · 1 comment · Fixed by #15
Labels
enhancement New feature or request

Comments

@francoischalifour
Copy link

Clearing Memento's cache must be done manually for the moment, there's no exposed API. A basic addition would be to add a clearCache option (see #8). This option however creates friction because you sometimes want to add to/update the cache without erasing all previous entries.

This is a proposal to add a way to rehydrate the cache.

New option

On top of this clearCache option, a common use case is to re-populate the responses coming from the hostUrl. You want to use that to get fresh responses from your host to use in your development environement.

A possible option name for this is:

$ memento --hydrate

Note that it's not very clear from this option name that it's a "watch" mode.

Example

In this example:

  • /api/v2/pokemon/pikachu is already cached
  • /api/v2/pokemon/electabuzz is not cached
$ memento --hydrate

[📼] Memento running @ http://localhost:3344
[📼] Memento configured to proxy to https://pokeapi.co with a delay of 0ms
[📼] Memento is run in hydrating mode. Each response already cached will be
     overwritten to the new response coming from the network. New entries will
     be added.

  <-- GET /api/v2/pokemon/pikachu
[📼](debug) Fetching response from the network
[📼](debug) Rehydrating response for /private/tmp/memento-example/.memento-cache-aHR0cHM6Ly9wb2tlYXBpLmNv/GET-_api_v2_pokemon_pikachu-9719b898ae4cc86d932840cefff21a8c7dec9eb9
  --> GET /api/v2/pokemon/pikachu 304 248ms

  <-- GET /api/v2/pokemon/electabuzz
[📼](debug) Fetching response from the network
[📼](debug) Persisting response for /private/tmp/memento-example/.memento-cache-aHR0cHM6Ly9wb2tlYXBpLmNv/GET-_api_v2_pokemon_electabuzz-72051936a11eab4b4820e1487f2cf35951447a08
  --> GET /api/v2/pokemon/electabuzz 200 790ms 180.15kb

In hydrating mode, although /api/v2/pokemon/pikachu was already cached, it's still fetched from the network and the cache response is overwritten. /api/v2/pokemon/electabuzz was not cached so it's fetched from the network and cached, as in the normal mode.

Alternative names

  • populate
  • register
  • overwrite
@antoinechalifour
Copy link
Owner

Love the idea, you're definitely right about this feature.

I'd love to suggest an alternative : if we decide to launch an interactive CLI (like Jest does), we could add a refresh option in the menu.

When selecting the refresh option, we then need to select the request, which can be fetched without the client needing to call memento (as we already have all the metadata in the cache to replay the request).

The UI would be something like that :

$ memento refresh
> Select the request you want to refresh :
- GET /pokemon/pikachu (at 14:22:34T00:00:00.000Z)
- GET /pokemon/tyranitar (at 14:22:34T00:00:00.000Z)
X GET /pokemon/electabuzz (at 14:22:34T00:00:00.000Z)

> Refreshing GET /pokemon/electabuzz data...
> Done

@antoinechalifour antoinechalifour added the enhancement New feature or request label Aug 15, 2019
antoinechalifour added a commit that referenced this issue Aug 16, 2019
antoinechalifour added a commit that referenced this issue Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants