Skip to content
v2.274.0

Cache Class ​

Cache options for CodeBuild Project.

A cache can store reusable pieces of your build environment and use them across multiple builds.

Example ​

ts
declare const vpc: ec2.Vpc;
declare const mySecurityGroup: ec2.SecurityGroup;
new pipelines.CodeBuildStep('Synth', {
  // ...standard ShellStep props...
  commands: [
    /* ... */
  ],
  env: {
    /* ... */
  },

  // If you are using a CodeBuildStep explicitly, set the 'cdk.out' directory
  // to be the synth step's output.
  primaryOutputDirectory: 'cdk.out',

  // Control the name of the project
  projectName: 'MyProject',

  // Control parts of the BuildSpec other than the regular 'build' and 'install' commands
  partialBuildSpec: codebuild.BuildSpec.fromObject({
    version: '0.2',
    // ...
  }),

  // Control the build environment
  buildEnvironment: {
    computeType: codebuild.ComputeType.LARGE,
    privileged: true,
    dockerServer: {
      computeType: codebuild.DockerServerComputeType.SMALL,
      securityGroups: [mySecurityGroup],
    },
  },
  timeout: Duration.minutes(90),
  fileSystemLocations: [
    codebuild.FileSystemLocation.efs({
      identifier: 'myidentifier2',
      location: 'myclodation.mydnsroot.com:/loc',
      mountPoint: '/media',
      mountOptions: 'opts',
    }),
  ],

  // Control Elastic Network Interface creation
  vpc: vpc,
  subnetSelection: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS },
  securityGroups: [mySecurityGroup],

  // Control caching
  cache: codebuild.Cache.bucket(new s3.Bucket(this, 'Cache')),

  // Additional policy statements for the execution role
  rolePolicyStatements: [
    new iam.PolicyStatement({
      /* ... */
    }),
  ],
});

Initializer ​

ts
new Cache()
python
Cache()
java
new Cache()
csharp
new Cache()
go
NewCache()

Methods ​

bucket(bucket: IBucket, options?: BucketCacheOptions): Cache // chainable@staticmethod def bucket(bucket: IBucket, options: typing.Optional[BucketCacheOptions] = None) -> Cachepublic static Cache bucket(IBucket bucket, BucketCacheOptions options)public static Cache Bucket(IBucket bucket, BucketCacheOptions? options = null)func Bucket(Bucket IBucket, Options BucketCacheOptions) Cachestatic#
Create an S3 caching strategy.
2 parameters

Parameters

  • bucketbucketbucketbucketBucket — the S3 bucket to use for caching.
  • optionsoptionsoptionsoptionsOptions — additional options to pass to the S3 caching.
local(...modes: LocalCacheMode[]): Cache // chainable@staticmethod def local(modes: LocalCacheMode) -> Cachepublic static Cache local(LocalCacheMode modes)public static Cache Local(LocalCacheMode modes)func Local(Modes LocalCacheMode) Cachestatic#
Create a local caching strategy.
1 parameter

Parameters

  • modesmodesmodesmodesModes — the mode(s) to enable for local caching.
none(): Cache // chainable@staticmethod def none() -> Cachepublic static Cache none()public static Cache None()func None() Cachestatic#