Memorystore Memcached (beta)

Memorystore Memcached Instance

Enable API

gcloud services enable servicenetworking.googleapis.com
gcloud services enable memcache.googleapis.com
circle-exclamation

Enable Private Service Access

Memorystore Memcached requires Private Services Access to be enabled. See Establishing a private services access connectionarrow-up-right documentation for more information.

Reserve an IP address range to be used in a VPC, so that the Memcached instance's IP address can be allocated within this range:

gcloud beta compute addresses create reserved-range \
  --global --prefix-length=24 \
  --description=description --network=default \
  --purpose=vpc_peering
circle-info

This is a simplified range creation on the default VPC network. In a production environment, you should verify what the range should be and which VPC network to allocate in.

Establish peering so that Memorystore can allocate the IP address in the reserved range in the VPC.

gcloud services vpc-peerings connect \
  --service=servicenetworking.googleapis.com \
  --ranges=reserved-range --network=default

Create an Instance

Create an instance and attach it to the default VPC.

circle-exclamation

Get Instance IP Address

circle-exclamation

Connect to Instance

See Memorystore connectivity options to see how to connect to a Memorystore instance from different computing environments.

You can test quickly by creating a Compute Engine instance in a zone within the same region:

SSH into the machine:

Install redis-cli:

Connect to the instance:

You can try different Memcached commands, for example, stats:

circle-info

See Memcached commandsarrow-up-right for more information.

Spring Boot Cache

Spring Boot does not have a built-in Memcached support. However you can use a 3rd party Memcached starter to provide Spring Boot cache support, e.g.:

Dependency

Add the 3rd party Memcached Spring Boot starter:

Configuration

Configure the Memcached instance to connect to:

Enable Caching

Turn on caching capability explicitly with the @EnableCaching annotation:

Cacheable

Once you configured the Spring Boot with Redis and enabled caching, you can use the @Cacheable annotation to cache return values.

Last updated

Was this helpful?