Skip to content

cache+retries #92

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

Merged
merged 1 commit into from
Jul 1, 2024
Merged
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
22 changes: 22 additions & 0 deletions src/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ export type Options = {
id?: Node["id"];
/** When true the server will omit this node's output. Default: false */
hide?: boolean;
/** Number of seconds to cache an output for this node's unique inputs. Default: null */
cache_age?: number;
/** Applies if cache_age > 0. Optionally specify a subset of keys to use when computing a cache key.
* Default: all node arguments
*/
cache_keys?: string[];
/** Max number of times to retry this node if it fails. Default: null means no retries */
max_retries?: number;
};

export abstract class Node {
Expand All @@ -22,6 +30,14 @@ export abstract class Node {
args: Object;
/** When true the server will omit this node's output. Default: false */
hide: boolean;
/** Number of seconds to cache an output for this node's unique inputs. Default: null */
cache_age?: number;
/** Applies if cache_age > 0. Optionally specify a subset of keys to use when computing a cache key.
* Default: all node arguments
*/
cache_keys?: string[];
/** Max number of times to retry this node if it fails. Default: null means no retries */
max_retries?: number;

/** TODO this field stores the last response, but it's just temporary until the internals are refactored */
protected _response: SubstrateResponse | undefined;
Expand All @@ -31,6 +47,9 @@ export abstract class Node {
this.args = args;
this.id = opts?.id || generator(this.node);
this.hide = opts?.hide || false;
this.cache_age = opts?.cache_age;
this.cache_keys = opts?.cache_keys;
this.max_retries = opts?.max_retries;
}

/**
Expand Down Expand Up @@ -103,6 +122,9 @@ export abstract class Node {
node: this.node,
args: withPlaceholders(this.args),
_should_output_globally: !this.hide,
...(this.cache_age && { _cache_age: this.cache_age }),
...(this.cache_keys && { _cache_keys: this.cache_keys }),
...(this.max_retries && { _max_retries: this.max_retries }),
};
}

Expand Down
Loading