Hibernate-arcus

hibernate 2nd cache implementation using Arcus as a shared cache storage

License

License

Categories

Categories

Hibernate Data ORM
GroupId

GroupId

com.github.kims-developergroup
ArtifactId

ArtifactId

hibernate-arcus
Last Version

Last Version

1.2.0-RELEASE
Release Date

Release Date

Type

Type

jar
Description

Description

Hibernate-arcus
hibernate 2nd cache implementation using Arcus as a shared cache storage
Project URL

Project URL

https://github.com/Kims-DeveloperGroup/hibernate-arcus
Source Code Management

Source Code Management

https://github.com/Kims-DeveloperGroup/hibernate-arcus

Download hibernate-arcus

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.kims-developergroup/hibernate-arcus/ -->
<dependency>
    <groupId>com.github.kims-developergroup</groupId>
    <artifactId>hibernate-arcus</artifactId>
    <version>1.2.0-RELEASE</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.kims-developergroup/hibernate-arcus/
implementation 'com.github.kims-developergroup:hibernate-arcus:1.2.0-RELEASE'
// https://jarcasting.com/artifacts/com.github.kims-developergroup/hibernate-arcus/
implementation ("com.github.kims-developergroup:hibernate-arcus:1.2.0-RELEASE")
'com.github.kims-developergroup:hibernate-arcus:jar:1.2.0-RELEASE'
<dependency org="com.github.kims-developergroup" name="hibernate-arcus" rev="1.2.0-RELEASE">
  <artifact name="hibernate-arcus" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.kims-developergroup', module='hibernate-arcus', version='1.2.0-RELEASE')
)
libraryDependencies += "com.github.kims-developergroup" % "hibernate-arcus" % "1.2.0-RELEASE"
[com.github.kims-developergroup/hibernate-arcus "1.2.0-RELEASE"]

Dependencies

compile (5)

Group / Artifact Type Version
com.navercorp.arcus : arcus-java-client jar 1.12.1
org.hibernate : hibernate-core jar 5.4.22.Final
org.projectlombok : lombok jar 1.18.4
org.slf4j : slf4j-api jar 1.7.30
ch.qos.logback : logback-classic jar 1.2.3

test (4)

Group / Artifact Type Version
junit : junit jar 4.12
org.hibernate : hibernate-testing jar 5.4.27.Final
org.assertj : assertj-core jar 3.18.1
com.h2database : h2 jar 1.4.200

Project Modules

There are no modules declared in this project.

hibernate-arcus

Hibernate 2nd Cache implemetation using Arcus cache cloud

Arcus is memcached based cache cloud
Hibernate second cache interface puts the result entities into a provided cache storage and reuse them without accessing a database.
hibernate-arcus offers an implementation, and employs arcus cache cloud as a cache storage



Quick Tutorial

1. Add the hibernate-arcus

Available in MavenCentral

<dependency>
  <groupId>com.github.kims-developergroup</groupId>
  <artifactId>hibernate-arcus</artifactId>
  <version>1.2.0-RELEASE</version>
</dependency>

Snapshot maven repository: https://oss.sonatype.org/content/repositories/snapshots/

2. Set the properties below

if you use spring jpa

//application.properties

spring.jpa.properties.hibernate.cache.region.factory_class=com.devookim.hibernatearcus.factory.HibernateArcusRegionFactory
spring.jpa.properties.hibernate.cache.use_second_level_cache=true
spring.jpa.properties.hibernate.cache.use_query_cache=true

spring.jpa.properties.hibernate.cache.arcus.serviceCode=${arcus_service_code}  # required
spring.jpa.properties.hibernate.cache.arcus.poolSize=${arcus_client_pool_size} # default poolSize=1
spring.jpa.properties.hibernate.cache.arcus.host=${hostName}:{$port}           # required

or if you use only hibernate

//hibernate.properties

hibernate.cache.region.factory_class=com.devookim.hibernatearcus.factory.HibernateArcusRegionFactory
hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=true

hibernate.cache.arcus.serviceCode=${arcus_service_code}  # required
hibernate.cache.arcus.poolSize=${arcus_client_pool_size} # default poolSize=1
hibernate.cache.arcus.host=${hostName}:{$port}           # required

In case that query cache is not required, and set hibernate.cache.use_query_cache=false
However, hibernate.cache.use_query_cache=true is necessary set with hibernate.cache.use_second_level_cache=true

3. How to use cache

  1. Attach @Cache annotation to an entity class
    Entities are cached with an id.
@Cache(usage = ${CacheConcurrencyStrategy}, region = "${regionName}")
public static class ParentDomainData implements Serializable {
  @Id
  long id;
...
}

Note: when changing CacheConcurrencyStrategy, regionName also should be modified not to reuse exsting cache items.
For more detail: When @Cache.usage changes, casting exception is thrown


  1. @NaturalId
    You may want to cache entities with a natural id, then attach @NaturalId annotation
@Cache(usage = ${CacheConcurrencyStrategy}, region = "${regionName}")
public static class ParentDomainData implements Serializable {
...
@NaturalId
long someNaturalId;
...
}
  1. @QueryHint
    You may want to cache queries, then attach @QueryHint
@QueryHints(value = {@QueryHint(value="true", name = HINT_CACHEABLE)})
    Optional<Entity> findByName(String name);



How to run tests

  1. Run arcus cache locally (DockerImage is ready here)

Just run the docker-compose in the project root

docker-compose up
gradlew clean test --info

Additional Configuration Properties

hibernate.cache.arcus.fallbackEnabled  (default: true) // whether to use fallback mode or not.
hibernate.cache.arcus.initFallbackMode (default: false) // Initial value of fallback mode
hibernate.cache.arcus.reconnectIntervalInSec (default: 10000) unit mills // ArcusClient retry connection interval in seconds
hibernate.cache.arcus.opTimeout (default 10000) unit mills // arcus client cache operation timeout.
hibernate.cache.arcus.healthCheckIntervalInSec(default 10) unit sec // interval time of health check
hibernate.cache.arcus.domainData.evictionRegionGroupOnCacheUpdate(default "") // domain data region group to be evicted on cache update

Contribution

Always welcome all shapes of your contribution and use-cases

com.github.kims-developergroup

Kim's Developers Group

Versions

Version
1.2.0-RELEASE
1.2.0
1.1.0-RELEASE
1.0.0-RELEASE