Couchbase – How to create Spring Cache Couchbase application with SpringBoot
couchbase
2
springboot
135
springcache
3
Male avatar

loveprogramming viết ngày 25/04/2021

https://grokonez.com/spring-framework/spring-data/couchbase-create-spring-cache-couchbase-application-springboot

Couchbase – How to create Spring Cache Couchbase application with SpringBoot

Performance is a big problem in software development. And Caching is one solution to speed up system. In the past post, We are familiar with Couchbase database by learning how to build Spring JPA Couchbase application. So in the tutorial, JavaSampleApproach will continue to show you how to create Spring Cache Couchbase application with SpringBoot.

Related posts:

I. Technologies

– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot: 1.5.6RELEASE
– Couchbase 4.6.2

II. Spring Cache Couchbase

We can use Couchbase as backing cache:

spring cache couchbase - architecture

For work with SpringCache Couchbase, we need a dependency:

<dependency>
    <groupId>com.couchbase.client</groupId>
    <artifactId>couchbase-spring-cache</artifactId>
</dependency>

How to configure Couchbase server as Cache?
-> We need to build a CacheManager with Couchbase cluster:


@EnableCaching
@Configuration
public class CacheConfig {

    ...
    
    @Bean(destroyMethod = "disconnect")
    public Cluster cluster() {
        return CouchbaseCluster.create(couchbaseServer);
    }

    @Bean(destroyMethod = "close")
    public Bucket bucket() {
        return cluster().openBucket(couchbaseBucket, couchbasePassword);
    }

    @Bean
    public CacheManager cacheManager() {
        CacheBuilder cacheBuilder = CacheBuilder.newInstance(bucket()).withExpiration(0);
        return new CouchbaseCacheManager(cacheBuilder, CACHE_NAME);
    }

}

@EnableCaching is used to enable the caching.

Document for Couchbase cache is built with Serializable:

More at:

https://grokonez.com/spring-framework/spring-data/couchbase-create-spring-cache-couchbase-application-springboot

Couchbase – How to create Spring Cache Couchbase application with SpringBoot

Bình luận


White
{{ comment.user.name }}
Bỏ hay Hay
{{comment.like_count}}
Male avatar
{{ comment_error }}
Hủy
   

Hiển thị thử

Chỉnh sửa

Male avatar

loveprogramming

444 bài viết.
77 người follow
Kipalog
{{userFollowed ? 'Following' : 'Follow'}}
Cùng một tác giả
Male avatar
1 0
Tutorial Link: (Link) (Ảnh) Django is a Pythonbased free and opensource web framework that follows the modeltemplateview architectural pattern. A...
loveprogramming viết 6 tháng trước
1 0
Male avatar
1 0
https://loizenai.com/angular11nodejspostgresqlcrudexample/ Angular 11 Node.js PostgreSQL Crud Example (Ảnh) Tutorial: “Angular 11 Node.js Postg...
loveprogramming viết 5 tháng trước
1 0
Male avatar
1 0
Angular Spring Boot jwt Authentication Example Github https://loizenai.com/angularspringbootjwt/ (Ảnh) Tutorial: ” Angular Spring Boot jwt Authe...
loveprogramming viết 5 tháng trước
1 0
Bài viết liên quan
Male avatar
0 0
https://grokonez.com/frontend/angular/angular6/kotlinspringbootangular6crudhttpclientmysqlexamplespringdatajparestapisexample Kotlin Spring Boot +...
loveprogramming viết 1 tháng trước
0 0
Male avatar
0 0
https://grokonez.com/springframework/springdata/couchbasecreatespringjpacouchbaseapplicationspringboot Couchbase server is an open source, distrib...
loveprogramming viết 1 tháng trước
0 0
{{like_count}}

kipalog

{{ comment_count }}

bình luận

{{liked ? "Đã kipalog" : "Kipalog"}}


Male avatar
{{userFollowed ? 'Following' : 'Follow'}}
444 bài viết.
77 người follow

 Đầu mục bài viết

Vẫn còn nữa! x

Kipalog vẫn còn rất nhiều bài viết hay và chủ đề thú vị chờ bạn khám phá!