Abstract the SessionCache and allow outside implementations.
This commit is contained in:
parent
62be0e6ccd
commit
a65b775faa
8 changed files with 21 additions and 152 deletions
|
@ -125,11 +125,6 @@
|
|||
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy:1.6.14" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy-agent:1.6.14" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:2.5" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: com.github.ben-manes.caffeine:jcache:2.5.6" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: javax.cache:cache-api:1.0.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: com.typesafe:config:1.3.1" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: javax.inject:javax.inject:1" level="project" />
|
||||
<orderEntry type="library" name="Maven: net.spy:spymemcached:2.12.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.1" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: org.slf4j:jcl-over-slf4j:1.7.1" level="project" />
|
||||
</component>
|
||||
|
|
14
pom.xml
14
pom.xml
|
@ -259,20 +259,6 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Caching -->
|
||||
<dependency>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
<artifactId>jcache</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.spy</groupId>
|
||||
<artifactId>spymemcached</artifactId>
|
||||
<version>2.12.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Logging -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
|
|
|
@ -190,7 +190,7 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
Object result = null;
|
||||
for (String[] combination : facetCombinations) {
|
||||
String cacheKey = tableName + "." + Arrays.toString(combination);
|
||||
result = sessionCache.getIfPresent(cacheKey);
|
||||
result = sessionCache.get(cacheKey);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import com.datastax.driver.core.*;
|
|||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
|
||||
import brave.Tracer;
|
||||
import net.helenus.core.cache.SessionCache;
|
||||
import net.helenus.core.reflect.DslExportable;
|
||||
import net.helenus.mapping.HelenusEntity;
|
||||
import net.helenus.mapping.HelenusEntityType;
|
||||
|
@ -56,6 +57,7 @@ public final class SessionInitializer extends AbstractSessionOperations {
|
|||
private boolean dropUnusedIndexes = false;
|
||||
private KeyspaceMetadata keyspaceMetadata;
|
||||
private AutoDdl autoDdl = AutoDdl.UPDATE;
|
||||
private SessionCache sessionCache = null;
|
||||
|
||||
SessionInitializer(Session session) {
|
||||
this.session = Objects.requireNonNull(session, "empty session");
|
||||
|
@ -123,6 +125,11 @@ public final class SessionInitializer extends AbstractSessionOperations {
|
|||
return this;
|
||||
}
|
||||
|
||||
public SessionInitializer setSessionCache(SessionCache sessionCache) {
|
||||
this.sessionCache = sessionCache;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConsistencyLevel getDefaultConsistencyLevel() {
|
||||
return consistencyLevel;
|
||||
}
|
||||
|
@ -243,8 +250,8 @@ public final class SessionInitializer extends AbstractSessionOperations {
|
|||
public synchronized HelenusSession get() {
|
||||
initialize();
|
||||
return new HelenusSession(session, usingKeyspace, registry, showCql, printStream, sessionRepository, executor,
|
||||
autoDdl == AutoDdl.CREATE_DROP, consistencyLevel, idempotent, unitOfWorkClass, metricRegistry,
|
||||
zipkinTracer);
|
||||
autoDdl == AutoDdl.CREATE_DROP, consistencyLevel, idempotent, unitOfWorkClass, sessionCache,
|
||||
metricRegistry, zipkinTracer);
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2015 The Helenus Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.helenus.core.cache;
|
||||
|
||||
public class CaffeineCache<K, V> implements SessionCache<K, V> {
|
||||
|
||||
|
||||
final Cache<K, V> cache;
|
||||
|
||||
CaffeineCache(Cache<K, V> cache) {
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate(K key) {
|
||||
cache.invalidate(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(K key) {
|
||||
return cache.getIfPresent(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(K key, V value) {
|
||||
cache.put(key, value);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2015 The Helenus Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.helenus.core.cache;
|
||||
|
||||
public class MemcacheDbCache<K, V> implements SessionCache<K, V> {
|
||||
//final Cache<K, V> cache;
|
||||
|
||||
MemcacheDbCache() {
|
||||
//this.cache = cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate(K key) {
|
||||
//cache.invalidate(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(K key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(K key, V value) {
|
||||
//cache.put(key, value);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2015 The Helenus Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.helenus.core.cache;
|
||||
|
||||
public class RedisCache<K, V> implements SessionCache<K, V> {
|
||||
//final Cache<K, V> cache;
|
||||
|
||||
RedisCache() {
|
||||
//this.cache = cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate(K key) {
|
||||
//cache.invalidate(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(K key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(K key, V value) {
|
||||
//cache.put(key, value);
|
||||
}
|
||||
|
||||
}
|
|
@ -36,6 +36,7 @@ import net.helenus.mapping.HelenusEntity;
|
|||
import net.helenus.mapping.HelenusProperty;
|
||||
import net.helenus.mapping.MappingUtil;
|
||||
import net.helenus.mapping.value.BeanColumnValueProvider;
|
||||
import net.helenus.mapping.value.ValueProviderMap;
|
||||
import net.helenus.support.HelenusMappingException;
|
||||
import net.helenus.support.Immutables;
|
||||
|
||||
|
@ -66,6 +67,7 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
this.draft = null;
|
||||
this.draftMap = null;
|
||||
this.pojo = pojo;
|
||||
this.entity = Helenus.resolve(MappingUtil.getMappingInterface(pojo));
|
||||
}
|
||||
|
||||
public UpdateOperation(AbstractSessionOperations sessionOperations, HelenusPropertyNode p, Object v) {
|
||||
|
@ -95,11 +97,15 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
}
|
||||
}
|
||||
|
||||
if (pojo != null && pojo instanceof MapExportable) {
|
||||
String key = prop.getPropertyName();
|
||||
Map<String, Object> map = ((MapExportable)pojo).toMap();
|
||||
if (map.get(key) != value) {
|
||||
map.put(key, value);
|
||||
if (entity != null) {
|
||||
if (entity.isCacheable() && pojo != null && pojo instanceof MapExportable) {
|
||||
String key = prop.getPropertyName();
|
||||
Map<String, Object> map = ((MapExportable) pojo).toMap();
|
||||
if (!(map instanceof ValueProviderMap)) {
|
||||
if (map.get(key) != value) {
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue