[JAVA] I tried to develop the cache function of Application Container Cloud Service in the local environment

Oracle Application Container Cloud Service provides caching functionality.

-I tried using the cache function of Application Container Cloud Service

The ** Local Cache ** feature is available to facilitate the development of this cache feature.

Description

Application Cache provided by Oracle Application Container Cloud Service gets the name of the running host from the environment variable and uses it as the cache destination. Therefore, in order to use the cache function, it is a prerequisite that the Application Cache instance is created and started on the Application Container Cloud Service.

-Reference: Cache initialization

It is inconvenient to connect remotely during development for testing and debugging. Therefore, use the ** LocalCache ** API provided by the Application Cache Client.

LocalCache

LocalCache provides an API similar to the API when using Cache on the actual Application Container Cloud Service.

ClassDiagram

As you can see from the class diagram above, ** AbstractCache ** that implements the ** Cache interface ** inherits the abstract class for ** REST ** processing, ** gRPC ** processing, ** local * * Each class for processing is created.

RestCache / GrpcCahe

The cache created in "I tried using the cache function of Application Container Cloud Service" has a ** REST ** type in the ** Transport ** class. It was specified. It is therefore defined as ** RestCache **.

cacheSession = sessionProvider.createSession(Transport.rest());

Also, if you specify a Transport type of ** gRPC **, it will be defined as ** GrpcCache **.

function

There is no difference in the basic functions of LocalCache, RestCache, and GrpcCache.

--Get cache

Premise

The following libraries are required to use the Java API for the cache service client application.

It can be obtained by describing the following dependency by Maven:

<dependency>
    <groupId>com.oracle.cloud.caching</groupId>
    <artifactId>cache-client-api</artifactId>
    <version>1.0.0</version>
</dependency>

Usage / Implementation example

It is convenient to switch the Cache used when running on Application Container Cloud Service and when running in a local environment. Therefore, let's use environment variables as identification information on Application Container Cloud Service or local environment.

In Application Container Cloud Servive, the directory name is registered in the environment variable ** APP_HOME ** as the information of the location where the deployed application file is placed. Therefore, we will use the presence or absence of this environment variable to determine the environment difference.

Before inserting the environment discrimination process

Session cacheSession = new RemoteSessionProvider(CACHE_URL).createSession(Transport.rest());
Cache cache = cacheSession.getCache(CACHE_NAME, ValueType.of(String.class));

After adding the environment discrimination process

SessionProvider sessionProvider = System.getenv(APP_HOME_DIR) == null ? new LocalSessionProvider() : new RemoteSessionProvider(CACHE_URL);
Session cacheSession = new RemoteSessionProvider(CACHE_URL).createSession(Transport.rest());
Cache cache = cacheSession.getCache(CACHE_NAME, ValueType.of(String.class));

The SessionProvider is switched depending on the presence or absence of environment variables.

Example of executing Application Cache in the local environment

Local access when using RestCache

Local access when using LocalCache

Summary

Until I noticed the existence of LocalCache, I was wondering if I would pull out the host name where Application Cache is running from the environment and develop it while connecting remotely. LocalCache helps you because you don't have to worry about remote connections during development.

Recommended Posts

I tried to develop the cache function of Application Container Cloud Service in the local environment
I tried to develop an application in 2 languages
After learning Progate, I tried to make an SNS application using Rails in the local environment
How to install Docker in the local environment of an existing Rails application [Rails 6 / MySQL 8]
[Swift] I tried to implement the function of the vending machine
I tried to build the environment of WSL2 + Docker + VSCode
I tried to implement Ajax processing of like function in Rails
I tried using Docker because I don't want to pollute the local environment in Microsoft Teams tab development of MS Learn
I tried to make the "Select File" button of the sample application created in the Rails tutorial cool
I tried to build a Firebase application development environment with Docker in 2020
I tried to make full use of the CPU core in Ruby
I tried to organize the session in Rails
How to set environment variables in the properties file of Spring boot application
I was addicted to the NoSuchMethodError in Cloud Endpoints
I tried to organize the cases used in programming
I tried using the Server Push function of Servlet 4.0
I tried to summarize the state transition of docker
05. I tried to stub the source of Spring Boot
I tried to reduce the capacity of Spring Boot
I tried to make a login function in Java
SSL in the local environment of Docker / Rails / puma
I tried to implement the Euclidean algorithm in Java
First AWS Lambda (I tried to see what kind of environment it works in)
I tried to make a web application that searches tweets with vue-word cloud and examines the tendency of what is written in the associated profile
I tried to make an application in 3 months from inexperienced
I tried to implement the like function by asynchronous communication
I finished watching The Rose of Versailles, so I tried to reproduce the ending song in Java
I tried to summarize the basics of kotlin and java
I tried to make the sample application into a microservice according to the idea of the book "Microservice Architecture".
I tried to touch the asset management application using the emulator of the distributed ledger Scalar DLT
I tried to summarize the basic grammar of Ruby briefly
I tried to build the environment little by little using docker
I tried to implement a buggy web application in Kotlin
I tried to make a client of RESAS-API in Java
I want to recreate the contents of assets from scratch in the environment built with capistrano
I tried to assemble from 0 while considering the table design of the day / week / month / overall ranking display function in terms of performance.
I tried to solve the problem of "multi-stage selection" with Ruby
I tried to summarize the words that I often see in docker-compose.yml
I tried to illuminate the Christmas tree in a life game
I tried to sort the data in descending order, ascending order / Rails
I tried to implement the image preview function with Rails / jQuery
I tried to check the operation of gRPC server with grpcurl
I want to display the images under assets/images in the production environment
ngrok --https communication in local environment (exposing the server to the outside)
I want to change the value of Attribute in Selenium of Ruby
I tried to solve the problem of Google Tech Dev Guide
I tried to explain the method
[Rails] I tried deleting the application
[Android] Develop a service that allows university students to check the operating status of buses circulating in the university.
I tried to make a sample program using the problem of database specialist in Domain Driven Design
I tried to make a parent class of a value object in Ruby
How to develop from VScode in a remote destination environment or a remote destination container environment
I tried to summarize the key points of gRPC design and development
Run Redmine in the local environment of Windows10 Pro-Use Docker Desktop for Windows
I tried to solve the tribonacci sequence problem in Ruby, with recursion.
How to solve the local environment construction of Ruby on Rails (MAC)!
I tried to visualize the access of Lambda → Athena with AWS X-Ray
I tried to make a talk application in Java using AI "A3RT"
[Ruby] I tried to summarize the methods that frequently appear in paiza
How to migrate a web application created in a local docker environment to AWS
[Ruby] I tried to summarize the methods that frequently appear in paiza ②