BucketCacheOptions

class aws_cdk.aws_codebuild.BucketCacheOptions(*, cache_namespace=None, prefix=None)

Bases: object

Parameters:
  • cache_namespace (Optional[str]) – Defines the scope of the cache. You can use this namespace to share a cache across multiple projects. Default: undefined - No cache namespace, which means that the cache is not shared across multiple projects.

  • prefix (Optional[str]) – The prefix to use to store the cache in the bucket.

ExampleMetadata:

infused

Example:

# source_bucket: s3.Bucket
# my_caching_bucket: s3.Bucket


codebuild.Project(self, "ProjectA",
    source=codebuild.Source.s3(
        bucket=source_bucket,
        path="path/to/source-a.zip"
    ),
    # configure the same bucket and path prefix
    cache=codebuild.Cache.bucket(my_caching_bucket,
        prefix="cache",
        # use the same cache namespace
        cache_namespace="cache-namespace"
    ),
    build_spec=codebuild.BuildSpec.from_object({
        "version": "0.2",
        "phases": {
            "build": {
                "commands": ["..."]
            }
        },
        # specify the same cache key and paths
        "cache": {
            "key": "unique-key",
            "paths": ["/root/cachedir/**/*"
            ]
        }
    })
)

codebuild.Project(self, "ProjectB",
    source=codebuild.Source.s3(
        bucket=source_bucket,
        path="path/to/source-b.zip"
    ),
    # configure the same bucket and path prefix
    cache=codebuild.Cache.bucket(my_caching_bucket,
        prefix="cache",
        # use the same cache namespace
        cache_namespace="cache-namespace"
    ),
    build_spec=codebuild.BuildSpec.from_object({
        "version": "0.2",
        "phases": {
            "build": {
                "commands": ["..."]
            }
        },
        # specify the same cache key and paths
        "cache": {
            "key": "unique-key",
            "paths": ["/root/cachedir/**/*"
            ]
        }
    })
)

Attributes

cache_namespace

Defines the scope of the cache.

You can use this namespace to share a cache across multiple projects.

Default:

undefined - No cache namespace, which means that the cache is not shared across multiple projects.

See:

https://docs.aws.amazon.com/codebuild/latest/userguide/caching-s3.html#caching-s3-sharing

prefix

The prefix to use to store the cache in the bucket.