# BucketCacheOptions

- Source: [`aws-codebuild/lib/cache.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-codebuild/lib/cache.ts#L6)
- Type last changed: v2.205.0 · 15 Jul 2025

## Example

```ts
declare const sourceBucket: s3.Bucket;
declare const myCachingBucket: s3.Bucket;

new codebuild.Project(this, 'ProjectA', {
  source: codebuild.Source.s3({
    bucket: sourceBucket,
    path: 'path/to/source-a.zip',
  }),
  // configure the same bucket and path prefix
  cache: codebuild.Cache.bucket(myCachingBucket, {
    prefix: 'cache',
    // use the same cache namespace
    cacheNamespace: 'cache-namespace',
  }),
  buildSpec: codebuild.BuildSpec.fromObject({
    version: '0.2',
    phases: {
      build: {
        commands: ['...'],
      },
    },
    // specify the same cache key and paths
    cache: {
      key: 'unique-key',
      paths: [
        '/root/cachedir/**/*',
      ],
    },
  }),
});

new codebuild.Project(this, 'ProjectB', {
  source: codebuild.Source.s3({
    bucket: sourceBucket,
    path: 'path/to/source-b.zip',
  }),
  // configure the same bucket and path prefix
  cache: codebuild.Cache.bucket(myCachingBucket, {
    prefix: 'cache',
    // use the same cache namespace
    cacheNamespace: 'cache-namespace',
  }),
  buildSpec: codebuild.BuildSpec.fromObject({
    version: '0.2',
    phases: {
      build: {
        commands: ['...'],
      },
    },
    // specify the same cache key and paths
    cache: {
      key: 'unique-key',
      paths: [
        '/root/cachedir/**/*',
      ],
    },
  }),
});
```

## Properties

- `cacheNamespace`: string — Defines the scope of the cache.

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

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

- `prefix`: string — The prefix to use to store the cache in the bucket.
