Skip to content

Commit

Permalink
Mark externalCache as deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkamyshev committed Feb 12, 2023
1 parent 90be139 commit 19e9626
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 29 deletions.
5 changes: 5 additions & 0 deletions .changeset/thirty-monkeys-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@farfetched/core': minor
---

Mark `externalCache` as deprecated
28 changes: 0 additions & 28 deletions apps/website/docs/api/operators/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,31 +58,3 @@ cache(query, {
adapter: someAdapter({ observability: { hit, miss, expired, evicted } }),
});
```

### External adapter for `cache`

To integrate `cache` with external cache storage (e.g. Redis), there is `externalCache` provider.

```ts
import { cache, externalCache } from '@farfetched/core';

cache(query, {
adapter: externalCache({
get: async ({ key }) => {
const result = await redis.get(key);

return JSON.parse(result);
},
set: async ({ key, value }) => {
await redis.set(key, JSON.stringify(value));
},
purge: async () => {
await redis.flushdb();
},
}),
});
```

::: warning
Due to external nature of the storage, `externalCache` supports only subset of observability events: `observability.hit` and `observability.miss`, any other event is not supported.
:::
6 changes: 5 additions & 1 deletion apps/website/docs/releases/0-8.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# v0.7
# v0.8

## Migration guide

Expand Down Expand Up @@ -38,4 +38,8 @@ function User() {

:::

### Do not use `externalCache` adapter

`externalCache` adapter is deprecated, write your own adapter instead [by recipe](/recipes/server_cache).

<!--@include: ./0-8.changelog.md-->
3 changes: 3 additions & 0 deletions packages/core/src/cache/adapters/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ interface NarrowObservability {
miss?: Event<{ key: string }>;
}

/**
* @deprecated Write your own adapter instead by recipe — https://farfetched.pages.dev/recipes/server_cache.html
*/
export function externalCache(config: {
get: (opts: {
key: string;
Expand Down

0 comments on commit 19e9626

Please sign in to comment.