Skip to content

Improved management of context caching #19797

@gillisandrew

Description

@gillisandrew

Describe the feature

Users need better tooling for managing context caching behaviors and for maintaining cdk.context.json cached values.

Use Case

Users regularly open issues regarding stale values being returned by ContextProvider-enabled features (e.g. Parameter.valueFromLookup). As AWS itself recommends commiting cdk.context.json to source control to ensure reproducible builds, additional tooling should support maintaining it as well as control caching behaviors of lookups in general.

Proposed Solution

  1. Accept a validity duration as part of the lookup, after which the value will be refreshed by the context provider.
export declare class StringParameter extends ParameterBase implements IStringParameter {
  static valueFromLookup(scope: Construct, parameterName: string, validity?: Duration): string;
}
  1. Accept filtering options for cdk context --reset <key or number> cli command. Allow wildcard key matching and environment-based filtering so unused values can be removed without impacting determinism of the synthesis.

If plugin-registered context-providers do eventually leave alpha, consider calling a staleness check with the cached values on context providers to support more complex cache-busting behaviors.

export interface ContextProviderPlugin {
    shouldRefresh(oldValue: any): Promise<boolean>;
    getValue(args: {
        [key: string]: any;
    }): Promise<any>;
}

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.19.0

Environment details (OS name and version, etc.)

Windows 11 (WSL2 Ubuntu 20.04)

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/coreRelated to core CDK functionality@aws-cdk/custom-resourcesRelated to AWS CDK Custom Resourceseffort/mediumMedium work item – several days of effortfeature-requestA feature should be added or improved.p2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions