Skip to content

Commit

Permalink
chore: Add missing docs files
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Oct 31, 2024
1 parent 7b0a26e commit dbee938
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 0 deletions.
Binary file not shown.
48 changes: 48 additions & 0 deletions docs/docs/reference/typescript-api/cache/cache-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: "CacheConfig"
isDefaultIndex: false
generated: true
---
<!-- This file was generated from the Vendure source. Do not modify. Instead, re-run the "docs:build" script -->
import MemberInfo from '@site/src/components/MemberInfo';
import GenerationInfo from '@site/src/components/GenerationInfo';
import MemberDescription from '@site/src/components/MemberDescription';


## CacheConfig

<GenerationInfo sourceFile="packages/core/src/cache/cache.ts" sourceLine="14" packageName="@vendure/core" since="3.1.0" />

Configuration for a new <a href='/reference/typescript-api/cache/#cache'>Cache</a> instance.

```ts title="Signature"
interface CacheConfig {
getKey: (id: string | number) => string;
options?: SetCacheKeyOptions;
}
```

<div className="members-wrapper">

### getKey

<MemberInfo kind="property" type={`(id: string | number) =&#62; string`} />

A function which generates a cache key from the given id.
This key will be used to store the value in the cache.

By convention, the key should be namespaced to avoid conflicts.

*Example*

```ts
getKey: id => `MyStrategy:getProductVariantIds:${id}`,
```
### options

<MemberInfo kind="property" type={`SetCacheKeyOptions`} />

Options available when setting the value in the cache.


</div>
80 changes: 80 additions & 0 deletions docs/docs/reference/typescript-api/cache/cache-service.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
title: "CacheService"
isDefaultIndex: false
generated: true
---
<!-- This file was generated from the Vendure source. Do not modify. Instead, re-run the "docs:build" script -->
import MemberInfo from '@site/src/components/MemberInfo';
import GenerationInfo from '@site/src/components/GenerationInfo';
import MemberDescription from '@site/src/components/MemberDescription';


## CacheService

<GenerationInfo sourceFile="packages/core/src/cache/cache.service.ts" sourceLine="20" packageName="@vendure/core" since="3.1.0" />

The CacheService is used to cache data in order to optimize performance.

Internally it makes use of the configured <a href='/reference/typescript-api/cache/cache-strategy#cachestrategy'>CacheStrategy</a> to persist
the cache into a key-value store.

```ts title="Signature"
class CacheService {
protected cacheStrategy: CacheStrategy;
constructor(configService: ConfigService)
createCache(config: CacheConfig) => Cache;
get(key: string) => Promise<T | undefined>;
set(key: string, value: T, options?: SetCacheKeyOptions) => Promise<void>;
delete(key: string) => Promise<void>;
invalidateTags(tags: string[]) => Promise<void>;
}
```

<div className="members-wrapper">

### cacheStrategy

<MemberInfo kind="property" type={`<a href='/reference/typescript-api/cache/cache-strategy#cachestrategy'>CacheStrategy</a>`} />


### constructor

<MemberInfo kind="method" type={`(configService: ConfigService) => CacheService`} />


### createCache

<MemberInfo kind="method" type={`(config: <a href='/reference/typescript-api/cache/cache-config#cacheconfig'>CacheConfig</a>) => <a href='/reference/typescript-api/cache/#cache'>Cache</a>`} />

Creates a new <a href='/reference/typescript-api/cache/#cache'>Cache</a> instance with the given configuration.

The `Cache` instance provides a convenience wrapper around the `CacheService`
methods.
### get

<MemberInfo kind="method" type={`(key: string) => Promise&#60;T | undefined&#62;`} />

Gets an item from the cache, or returns undefined if the key is not found, or the
item has expired.
### set

<MemberInfo kind="method" type={`(key: string, value: T, options?: SetCacheKeyOptions) => Promise&#60;void&#62;`} />

Sets a key-value pair in the cache. The value must be serializable, so cannot contain
things like functions, circular data structures, class instances etc.

Optionally a "time to live" (ttl) can be specified, which means that the key will
be considered stale after that many milliseconds.
### delete

<MemberInfo kind="method" type={`(key: string) => Promise&#60;void&#62;`} />

Deletes an item from the cache.
### invalidateTags

<MemberInfo kind="method" type={`(tags: string[]) => Promise&#60;void&#62;`} />

Deletes all items from the cache which contain at least one matching tag.


</div>
62 changes: 62 additions & 0 deletions docs/docs/reference/typescript-api/cache/cache-strategy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
title: "CacheStrategy"
isDefaultIndex: false
generated: true
---
<!-- This file was generated from the Vendure source. Do not modify. Instead, re-run the "docs:build" script -->
import MemberInfo from '@site/src/components/MemberInfo';
import GenerationInfo from '@site/src/components/GenerationInfo';
import MemberDescription from '@site/src/components/MemberDescription';


## CacheStrategy

<GenerationInfo sourceFile="packages/core/src/config/system/cache-strategy.ts" sourceLine="36" packageName="@vendure/core" since="3.1.0" />

The CacheStrategy defines how the underlying shared cache mechanism is implemented.

It is used by the <a href='/reference/typescript-api/cache/cache-service#cacheservice'>CacheService</a> to take care of storage and retrieval of items
from the cache.

```ts title="Signature"
interface CacheStrategy extends InjectableStrategy {
get<T extends JsonCompatible<T>>(key: string): Promise<T | undefined>;
set<T extends JsonCompatible<T>>(key: string, value: T, options?: SetCacheKeyOptions): Promise<void>;
delete(key: string): Promise<void>;
invalidateTags(tags: string[]): Promise<void>;
}
```
* Extends: <code><a href='/reference/typescript-api/common/injectable-strategy#injectablestrategy'>InjectableStrategy</a></code>



<div className="members-wrapper">

### get

<MemberInfo kind="method" type={`(key: string) => Promise&#60;T | undefined&#62;`} />

Gets an item from the cache, or returns undefined if the key is not found, or the
item has expired.
### set

<MemberInfo kind="method" type={`(key: string, value: T, options?: SetCacheKeyOptions) => Promise&#60;void&#62;`} />

Sets a key-value pair in the cache. The value must be serializable, so cannot contain
things like functions, circular data structures, class instances etc.

Optionally a "time to live" (ttl) can be specified, which means that the key will
be considered stale after that many milliseconds.
### delete

<MemberInfo kind="method" type={`(key: string) => Promise&#60;void&#62;`} />

Deletes an item from the cache.
### invalidateTags

<MemberInfo kind="method" type={`(tags: string[]) => Promise&#60;void&#62;`} />

Deletes all items from the cache which contain at least one matching tag.


</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
title: "RequestContextCacheService"
isDefaultIndex: false
generated: true
---
<!-- This file was generated from the Vendure source. Do not modify. Instead, re-run the "docs:build" script -->
import MemberInfo from '@site/src/components/MemberInfo';
import GenerationInfo from '@site/src/components/GenerationInfo';
import MemberDescription from '@site/src/components/MemberDescription';


## RequestContextCacheService

<GenerationInfo sourceFile="packages/core/src/cache/request-context-cache.service.ts" sourceLine="15" packageName="@vendure/core" />

This service is used to cache arbitrary data relative to an ongoing request.
It does this by using a WeakMap bound to the current RequestContext, so the cached
data is available for the duration of the request. Once the request completes, the
cached data will be automatically garbage-collected.

This is useful for caching data which is expensive to compute and which is needed
multiple times during the handling of a single request.

```ts title="Signature"
class RequestContextCacheService {
set(ctx: RequestContext, key: any, val: T) => void;
get(ctx: RequestContext, key: any) => T | undefined;
get(ctx: RequestContext, key: any, getDefault?: () => T) => T;
get(ctx: RequestContext, key: any, getDefault?: () => T) => T | Promise<T> | undefined;
}
```

<div className="members-wrapper">

### set

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, key: any, val: T) => void`} />

Set a value in the RequestContext cache.
### get

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, key: any) => T | undefined`} />

Get a value from the RequestContext cache. If the value is not found, the `getDefault`
function will be called to get the value, which will then be cached and returned.
### get

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, key: any, getDefault?: () =&#62; T) => T`} />


### get

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, key: any, getDefault?: () =&#62; T) => T | Promise&#60;T&#62; | undefined`} />




</div>

0 comments on commit dbee938

Please sign in to comment.