> **Experimental**
>
> `@aws-cdk/aws-elasticache-alpha` is an [**experimental**](/stability) (alpha) package: its API may change in any release, without a major version bump.
# ServerlessCache

A serverless ElastiCache cache.

Extends: Construct › Resource › ServerlessCacheBase › ServerlessCache
Implements: IServerlessCache, IResource, IConnectable, IEnvironmentAware, IServerlessCacheRef, IConstruct, IDependable

- Stability: [Experimental](/cdk/api/stability.html)
- CloudFormation: [`AWS::ElastiCache::ServerlessCache`](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-elasticache-serverlesscache.html)
- L1 type: [`CfnServerlessCache`](/cdk/api/v2/docs/aws-cdk-lib.aws_elasticache.CfnServerlessCache.html)
- Source: [`lib/serverless-cache.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0-alpha.0/packages/@aws-cdk/aws-elasticache-alpha/lib/serverless-cache.ts#L240)

## Example

```ts
declare const vpc: ec2.Vpc;

const serverlessCache = new elasticache.ServerlessCache(this, 'ServerlessCache', {
  engine: elasticache.CacheEngine.VALKEY_LATEST,
  backup: {
    // set a backup name before deleting a cache
    backupNameBeforeDeletion: "my-final-backup-name",
  },
  vpc,
});
```

## Initializer

```ts
new ServerlessCache(scope: Construct, id: string, props: ServerlessCacheProps)
```

## Construct Props

- `backup`: [BackupSettings](/cdk/api/v2/docs/@aws-cdk_aws-elasticache-alpha.BackupSettings.html) — Backup configuration.

  **Default:** No backups configured

- `cacheUsageLimits`: [CacheUsageLimitsProperty](/cdk/api/v2/docs/@aws-cdk_aws-elasticache-alpha.CacheUsageLimitsProperty.html) — Usage limits for the cache.

  **Default:** No usage limits

- `description`: string — A description for the cache.

  **Default:** No description

- `engine`: [CacheEngine](/cdk/api/v2/docs/@aws-cdk_aws-elasticache-alpha.CacheEngine.html) — The cache engine combined with the version Enum options: VALKEY_DEFAULT, VALKEY_7, VALKEY_8, REDIS_DEFAULT, MEMCACHED_DEFAULT The default options bring the latest versions available.

  **Default:** when not provided, the default engine would be Valkey, latest version available (VALKEY_DEFAULT)

- `kmsKey`: [IKey](/cdk/api/v2/docs/aws-cdk-lib.aws_kms.IKey.html) — KMS key for encryption.

  **Default:** Service managed encryption (AWS owned KMS key)

- `securityGroups`: [ISecurityGroup](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISecurityGroup.html)[] — Security groups for the cache.

  **Default:** A new security group is created

- `serverlessCacheName`: string — Name for the serverless cache.

  **Default:** automatically generated name by Resource

- `userGroup`: [IUserGroup](/cdk/api/v2/docs/@aws-cdk_aws-elasticache-alpha.IUserGroup.html) — User group for access control.

  **Default:** No user group

- `vpc`: [IVpc](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html) (required) — The VPC to place the cache in.

- `vpcSubnets`: [SubnetSelection](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.SubnetSelection.html) — Which subnets to place the cache in.

  **Default:** Private subnets with egress

## Properties

- `backupArnsToRestore`: string[] — The ARNs of backups restored in the cache.

- `connections`: [Connections](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Connections.html) — Access to network connections.

- `engine`: [CacheEngine](/cdk/api/v2/docs/@aws-cdk_aws-elasticache-alpha.CacheEngine.html) — The cache engine used by this cache.

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) — The environment this resource belongs to.

  For resources that are created and managed in a Stack (those created by
  creating new class instances like `new Role()`, `new Bucket()`, etc.), this
  is always the same as the environment of the stack they belong to.

  For referenced resources (those obtained from referencing methods like
  `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
  different than the stack they were imported into.

- `grants`: [ServerlessCacheGrants](/cdk/api/v2/docs/@aws-cdk_aws-elasticache-alpha.ServerlessCacheGrants.html) — Collection of grant methods for this cache.

- `kmsKey`: [IKey](/cdk/api/v2/docs/aws-cdk-lib.aws_kms.IKey.html) — The KMS key used for encryption.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `PROPERTY_INJECTION_ID`: string (static) — Uniquely identifies this class.

- `securityGroups`: [ISecurityGroup](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISecurityGroup.html)[] — The security groups associated with this cache.

- `serverlessCacheArn`: string — The ARN of the serverless cache.

- `serverlessCacheEndpointAddress`: string — The endpoint address of the serverless cache.

- `serverlessCacheEndpointPort`: string — The endpoint port of the serverless cache.

- `serverlessCacheName`: string — The name of the serverless cache.

- `serverlessCacheReaderEndpointAddress`: string — The reader endpoint address of the serverless cache.

- `serverlessCacheReaderEndpointPort`: string — The reader endpoint port of the serverless cache.

- `serverlessCacheRef`: [ServerlessCacheReference](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_elasticache.ServerlessCacheReference.html) — A reference to a ServerlessCache resource.

- `serverlessCacheStatus`: string — The current status of the serverless cache Can be 'CREATING', 'AVAILABLE', 'DELETING', 'CREATE-FAILED', 'MODIFYING'.

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) — The stack in which this resource is defined.

- `subnets`: [ISubnet](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISubnet.html)[] — The subnets this cache is deployed in.

- `userGroup`: [IUserGroup](/cdk/api/v2/docs/@aws-cdk_aws-elasticache-alpha.IUserGroup.html) — The user group associated with this cache.

- `vpc`: [IVpc](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html) — The VPC this cache is deployed in.

## Methods

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Override the cross-stack reference strength for this resource.

  When set, any cross-stack reference to this resource will use the specified
  mechanism instead of the global default determined by the
  `@aws-cdk/core:defaultCrossStackReferences` context key. This is useful for
  selectively weakening specific references to avoid the "deadly embrace" problem
  without changing the app-wide default.

  **Parameters**

  - `strength` — - The reference strength to use for this resource.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — Apply the given removal policy to this resource.

  The Removal Policy controls what happens to this resource when it stops
  being managed by CloudFormation, either because you've removed it from the
  CDK application or because you've made a change that requires the resource
  to be replaced.

  The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
  account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).

- `fromServerlessCacheArn(scope: Construct, id: string, serverlessCacheArn: string): IServerlessCache` (static) — Import an existing serverless cache by ARN.

  **Parameters**

  - `scope` — The parent creating construct (usually `this`).
  - `id` — The construct's name.
  - `serverlessCacheArn` — The ARN of the existing serverless cache.

- `fromServerlessCacheAttributes(scope: Construct, id: string, attrs: ServerlessCacheAttributes): IServerlessCache` (static) — Import an existing serverless cache using attributes.

  **Parameters**

  - `scope` — The parent creating construct (usually `this`).
  - `id` — The construct's name.
  - `attrs` — A `ServerlessCacheAttributes` object.

- `fromServerlessCacheName(scope: Construct, id: string, serverlessCacheName: string): IServerlessCache` (static) — Import an existing serverless cache by name.

  **Parameters**

  - `scope` — The parent creating construct (usually `this`).
  - `id` — The construct's name.
  - `serverlessCacheName` — The name of the existing serverless cache.

- `grant(grantee: IGrantable, ...actions: string[]): Grant` — Grant the given identity custom permissions [disable-awslint:no-grants].

  **Parameters**

  - `grantee` — The principal to grant permissions to.
  - `actions` — The actions to grant.

- `grantConnect(grantee: IGrantable): Grant` — Grant connect permissions to the cache [disable-awslint:no-grants].

  **Parameters**

  - `grantee` — The principal to grant permissions to.

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `isOwnedResource(construct: IConstruct): boolean` (static) — Returns true if the construct was created by CDK, and false otherwise.

- `isResource(construct: IConstruct): boolean` (static) — Check whether the given construct is a Resource.

- `isServerlessCache(x: any): boolean` (static) — Return whether the given object is a `ServerlessCache`.

- `metric(metricName: string, props?: MetricOptions): Metric` — Return the given named metric for this cache.

  **Parameters**

  - `metricName` — The name of the metric.
  - `props` — Additional properties which will be merged with the default metric.

- `metricActiveConnections(props?: MetricOptions): Metric` — Metric for active connections.

  **Parameters**

  - `props` — Additional properties which will be merged with the default metric.

- `metricCacheHitCount(props?: MetricOptions): Metric` — Metric for cache hit count.

  **Parameters**

  - `props` — Additional properties which will be merged with the default metric.

- `metricCacheHitRate(props?: MetricOptions): Metric` — Metric for cache hit rate.

  **Parameters**

  - `props` — Additional properties which will be merged with the default metric.

- `metricCacheMissCount(props?: MetricOptions): Metric` — Metric for cache miss count.

  **Parameters**

  - `props` — Additional properties which will be merged with the default metric.

- `metricDataStored(props?: MetricOptions): Metric` — Metric for data stored in the cache.

  **Parameters**

  - `props` — Additional properties which will be merged with the default metric.

- `metricNetworkBytesIn(props?: MetricOptions): Metric` — Metric for network bytes in.

  **Parameters**

  - `props` — Additional properties which will be merged with the default metric.

- `metricNetworkBytesOut(props?: MetricOptions): Metric` — Metric for network bytes out.

  **Parameters**

  - `props` — Additional properties which will be merged with the default metric.

- `metricProcessingUnitsConsumed(props?: MetricOptions): Metric` — Metric for ECPUs consumed.

  **Parameters**

  - `props` — Additional properties which will be merged with the default metric.

- `metricReadRequestLatency(props?: MetricOptions): Metric` — Metric for read request latency.

  **Parameters**

  - `props` — Additional properties which will be merged with the default metric.

- `metricWriteRequestLatency(props?: MetricOptions): Metric` — Metric for write request latency.

  **Parameters**

  - `props` — Additional properties which will be merged with the default metric.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.
