Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions benchmarks/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5664,9 +5664,9 @@ __metadata:
linkType: hard

"lodash@npm:^4.14.0, lodash@npm:^4.17.11, lodash@npm:^4.17.12, lodash@npm:^4.17.14, lodash@npm:^4.17.15, lodash@npm:^4.17.21, lodash@npm:^4.17.4":
version: 4.17.21
resolution: "lodash@npm:4.17.21"
checksum: 10/c08619c038846ea6ac754abd6dd29d2568aa705feb69339e836dfa8d8b09abbb2f859371e86863eda41848221f9af43714491467b5b0299122431e202bb0c532
version: 4.17.23
resolution: "lodash@npm:4.17.23"
checksum: 10/82504c88250f58da7a5a4289f57a4f759c44946c005dd232821c7688b5fcfbf4a6268f6a6cdde4b792c91edd2f3b5398c1d2a0998274432cff76def48735e233
languageName: node
linkType: hard

Expand Down
20 changes: 16 additions & 4 deletions docs/docs/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,17 @@ Only `GET` endpoints are cached. Also, HTTP server routes that use the native re
@@PlatformCacheInterceptor@@.
:::

::: tip Force refresh
Send the `Cache-Control: no-cache` header with your request (or set the same header on the @@PlatformContext@@) to
bypass @@PlatformCacheInterceptor@@ temporarily. This lets you fetch a fresh response without clearing the cache and is
useful for debugging, warm-up scripts, or administrative tooling. You can override this behavior via the `byPass`
option on @@UseCache@@:

- Services/methods that aren't tied to HTTP default to `byPass: false`, meaning caching is always considered unless you opt out.
- Controllers/endpoints default to `byPass: "no-cache"`, so sending `Cache-Control: no-cache` skips both the lookup and write for that request without touching existing entries.
- Supply a predicate `byPass: (args, $ctx) => boolean` when you need finer control (tenant-based bypass, admin flag, etc.).
:::

## Cache a value

Because @@UseCache@@ uses @@PlatformCacheInterceptor@@ and not a middleware, you can also apply the decorator on any
Expand Down Expand Up @@ -450,9 +461,9 @@ background if current `ttl` is under 45 minutes.

## Refresh cached value <Badge text="7.9.0+" />

A service method response can be cached by using the `@UseCache` decorator. Sometimes, we need to explicitly refresh the cached data because the consumed data backend state has changed.
because the consumed data backend state has changed. By implementing a notifications service, the backend data can trigger an event to tell your API that
the data has changed.
A service method response can be cached by using the `@UseCache` decorator. Sometimes, we need to explicitly refresh the
cached data because the consumed data backend state has changed. By implementing a notifications service, the backend
data can trigger an event to tell your API that the data has changed.

Here is short example:

Expand Down Expand Up @@ -491,7 +502,8 @@ export class NotificationsService {
This small example will force the data refresh.

::: tip
If you have several cached method calls, then the refresh will also be done on all of these methods called by the function passed to `PlatformCache.refresh()`.
If you have several cached method calls, then the refresh will also be done on all of these methods called by the
function passed to `PlatformCache.refresh()`.
:::

## Multi caching
Expand Down
2 changes: 1 addition & 1 deletion packages/di/src/common/interfaces/InterceptorContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface InterceptorNext {
export interface InterceptorContext<Klass = Type, Opts = any> {
target: Klass;
propertyKey: string | symbol;
args: any[];
args: unknown[];
next: InterceptorNext;
options?: Opts;
}
10 changes: 10 additions & 0 deletions packages/platform/platform-cache/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ A package of Ts.ED framework. See website: https://tsed.devdocs/cache.html
npm install --save @tsed/platform-cache
```

## Force refresh

Send the header `Cache-Control: no-cache` (or set it directly on the `PlatformContext`) to bypass
`PlatformCacheInterceptor` for a single request. This is handy when you want a fresh response without wiping the cache.
You can override or extend this behavior with the `byPass` option on `@UseCache`:

- Service methods default to `byPass: false`, so they always consult the cache unless you explicitly return `true` from your predicate.
- HTTP endpoints default to `byPass: "no-cache"`, which automatically honours the `Cache-Control: no-cache` header for one-off refreshes.
- Provide a function (`byPass: (args, $ctx) => boolean`) to build custom strategies (e.g., bypass for admins or based on payload).

## Contributors

Please read [contributing guidelines here](https://tsed.devcontributing.html).
Expand Down
Loading
Loading