Skip to content
v2.277.0

LocalCacheMode Enum ​

Local cache modes to enable for the CodeBuild Project.

Example ​

ts
new codebuild.Project(this, 'Project', {
  source: codebuild.Source.gitHubEnterprise({
    httpsCloneUrl: 'https://my-github-enterprise.com/owner/repo',
  }),

  // Enable Docker AND custom caching
  cache: codebuild.Cache.local(codebuild.LocalCacheMode.DOCKER_LAYER, codebuild.LocalCacheMode.CUSTOM),

  // BuildSpec with a 'cache' section necessary for 'CUSTOM' caching. This can
  // also come from 'buildspec.yml' in your source.
  buildSpec: codebuild.BuildSpec.fromObject({
    version: '0.2',
    phases: {
      build: {
        commands: ['...'],
      },
    },
    cache: {
      paths: [
        // The '**/*' is required to indicate all files in this directory
        '/root/cachedir/**/*',
      ],
    },
  }),
});
python
codebuild.Project(self, "Project",
    source=codebuild.Source.git_hub_enterprise(
        https_clone_url="https://my-github-enterprise.com/owner/repo"
    ),

    # Enable Docker AND custom caching
    cache=codebuild.Cache.local(codebuild.LocalCacheMode.DOCKER_LAYER, codebuild.LocalCacheMode.CUSTOM),

    # BuildSpec with a 'cache' section necessary for 'CUSTOM' caching. This can
    # also come from 'buildspec.yml' in your source.
    build_spec=codebuild.BuildSpec.from_object({
        "version": "0.2",
        "phases": {
            "build": {
                "commands": ["..."]
            }
        },
        "cache": {
            "paths": ["/root/cachedir/**/*"
            ]
        }
    })
)
java
Project.Builder.create(this, "Project")
        .source(Source.gitHubEnterprise(GitHubEnterpriseSourceProps.builder()
                .httpsCloneUrl("https://my-github-enterprise.com/owner/repo")
                .build()))

        // Enable Docker AND custom caching
        .cache(Cache.local(LocalCacheMode.DOCKER_LAYER, LocalCacheMode.CUSTOM))

        // BuildSpec with a 'cache' section necessary for 'CUSTOM' caching. This can
        // also come from 'buildspec.yml' in your source.
        .buildSpec(BuildSpec.fromObject(Map.of(
                "version", "0.2",
                "phases", Map.of(
                        "build", Map.of(
                                "commands", List.of("..."))),
                "cache", Map.of(
                        "paths", List.of("/root/cachedir/**/*")))))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
new Project(this, "Project", new ProjectProps {
    Source = Source.GitHubEnterprise(new GitHubEnterpriseSourceProps {
        HttpsCloneUrl = "https://my-github-enterprise.com/owner/repo"
    }),

    // Enable Docker AND custom caching
    Cache = Cache.Local(LocalCacheMode.DOCKER_LAYER, LocalCacheMode.CUSTOM),

    // BuildSpec with a 'cache' section necessary for 'CUSTOM' caching. This can
    // also come from 'buildspec.yml' in your source.
    BuildSpec = BuildSpec.FromObject(new Dictionary<string, object> {
        { "version", "0.2" },
        { "phases", new Dictionary<string, IDictionary<string, string[]>> {
            { "build", new Struct {
                Commands = new [] { "..." }
            } }
        } },
        { "cache", new Dictionary<string, string[]> {
            { "paths", new [] { "/root/cachedir/**/*" } }
        } }
    })
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
codebuild.NewProject(this, jsii.String("Project"), &ProjectProps{
	Source: codebuild.Source_GitHubEnterprise(&GitHubEnterpriseSourceProps{
		HttpsCloneUrl: jsii.String("https://my-github-enterprise.com/owner/repo"),
	}),

	// Enable Docker AND custom caching
	Cache: codebuild.Cache_Local(codebuild.LocalCacheMode_DOCKER_LAYER, codebuild.LocalCacheMode_CUSTOM),

	// BuildSpec with a 'cache' section necessary for 'CUSTOM' caching. This can
	// also come from 'buildspec.yml' in your source.
	BuildSpec: codebuild.BuildSpec_FromObject(map[string]interface{}{
		"version": jsii.String("0.2"),
		"phases": map[string]map[string][]*string{
			"build": map[string][]*string{
				"commands": []*string{
					jsii.String("..."),
				},
			},
		},
		"cache": map[string][]*string{
			"paths": []*string{
				jsii.String("/root/cachedir/**/*"),
			},
		},
	}),
})

Members ​

MemberDescription
SOURCECaches Git metadata for primary and secondary sources.
DOCKER_LAYERCaches existing Docker layers.
CUSTOMCaches directories you specify in the buildspec file.