https://github.com/kims-developergroup/hibernate-arcus
Hibernate 2nd cache implementation using Arcus cache
https://github.com/kims-developergroup/hibernate-arcus
arcus arcus-cache arcus-cloud cache-storage help-welcome helpwanted hibernate hibernate2nd-level-cache jumpin
Last synced: 5 months ago
JSON representation
Hibernate 2nd cache implementation using Arcus cache
- Host: GitHub
- URL: https://github.com/kims-developergroup/hibernate-arcus
- Owner: Kims-DeveloperGroup
- Created: 2021-01-03T10:59:12.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-12-28T15:06:53.000Z (over 4 years ago)
- Last Synced: 2024-05-06T04:29:26.507Z (about 2 years ago)
- Topics: arcus, arcus-cache, arcus-cloud, cache-storage, help-welcome, helpwanted, hibernate, hibernate2nd-level-cache, jumpin
- Language: Java
- Homepage:
- Size: 90.8 KB
- Stars: 4
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# hibernate-arcus
### Hibernate 2nd Cache implemetation using [Arcus cache cloud](https://github.com/naver/arcus)
_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](https://search.maven.org/artifact/com.github.kims-developergroup/hibernate-arcus/1.2.0-RELEASE/jar)
```
com.github.kims-developergroup
hibernate-arcus
1.2.0-RELEASE
```
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](https://github.com/Kims-DeveloperGroup/hibernate-arcus/issues/1)_
2. @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;
...
}
```
3. @QueryHint
You may want to cache queries, then attach @QueryHint
```
@QueryHints(value = {@QueryHint(value="true", name = HINT_CACHEABLE)})
Optional findByName(String name);
```
----
### How to run tests
1. Run arcus cache locally _(DockerImage is ready [here](https://hub.docker.com/repository/docker/devookim/arcus-memcached))_
Just run the docker-compose in the project root
```
docker-compose up
```
2.
```
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_