Skip to content

Commit 588d734

Browse files
committed
add separate property for cacheLockTimeout
1 parent fd88842 commit 588d734

File tree

8 files changed

+23
-14
lines changed

8 files changed

+23
-14
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.github.mihaicostin</groupId>
66
<artifactId>hibernate-l2-memcached</artifactId>
7-
<version>1.1.0</version>
7+
<version>4.3.11.0</version>
88
<name>hibernate-l2-memcached</name>
99
<description>A library for using Memcached as a second level distributed cache in Hibernate.</description>
1010
<url>https://github.com/mihaicostin/hibernate-l2-memcached</url>

src/main/java/com/mc/hibernate/memcached/MemcachedRegionFactory.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ public long nextTimestamp() {
8383
}
8484

8585
public EntityRegion buildEntityRegion(String regionName, Properties properties, CacheDataDescription metadata) throws CacheException {
86-
return new MemcachedEntityRegion(getCache(regionName), settings,
87-
metadata, properties, client);
86+
return new MemcachedEntityRegion(getCache(regionName), settings, metadata, properties, client);
8887
}
8988

9089
public NaturalIdRegion buildNaturalIdRegion(String regionName, Properties properties, CacheDataDescription metadata) throws CacheException {
@@ -96,11 +95,11 @@ public CollectionRegion buildCollectionRegion(String regionName, Properties prop
9695
}
9796

9897
public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties properties) throws CacheException {
99-
return new MemcachedQueryResultsRegion(getCache(regionName));
98+
return new MemcachedQueryResultsRegion(getCache(regionName), properties);
10099
}
101100

102101
public TimestampsRegion buildTimestampsRegion(String regionName, Properties properties) throws CacheException {
103-
return new MemcachedTimestampsRegion(getCache(regionName));
102+
return new MemcachedTimestampsRegion(getCache(regionName), properties);
104103
}
105104

106105
protected MemcacheClientFactory getMemcachedClientFactory(Config config) {

src/main/java/com/mc/hibernate/memcached/region/AbstractMemcachedRegion.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,19 @@
2121

2222
import java.util.Collections;
2323
import java.util.Map;
24+
import java.util.Properties;
2425

2526
public abstract class AbstractMemcachedRegion implements Region {
2627

28+
private static final int DEFAULT_CACHE_LOCK_TIMEOUT = 60000;
29+
private final int lockTimeout;
30+
2731
protected MemcachedCache cache;
2832

29-
AbstractMemcachedRegion(MemcachedCache cache) {
33+
AbstractMemcachedRegion(MemcachedCache cache, Properties properties) {
3034
this.cache = cache;
35+
String property = properties.getProperty("hibernate.memcached.cacheLockTimeout", String.valueOf(DEFAULT_CACHE_LOCK_TIMEOUT));
36+
this.lockTimeout = Integer.decode(property);
3137
}
3238

3339
public String getName() {
@@ -73,7 +79,7 @@ public long nextTimestamp() {
7379
* @return timeout in ms
7480
*/
7581
public int getTimeout() {
76-
return cache.getTimeoutSeconds() * 1000;
82+
return lockTimeout;
7783
}
7884

7985
public MemcachedCache getCache() {

src/main/java/com/mc/hibernate/memcached/region/MemcachedCollectionRegion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class MemcachedCollectionRegion extends AbstractMemcachedRegion implement
4040
private final Settings settings;
4141

4242
public MemcachedCollectionRegion(MemcachedCache cache, Settings settings, CacheDataDescription metadata, Properties properties, Memcache client) {
43-
super(cache);
43+
super(cache, properties);
4444
this.metadata = metadata;
4545
this.settings = settings;
4646
}

src/main/java/com/mc/hibernate/memcached/region/MemcachedEntityRegion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class MemcachedEntityRegion extends AbstractMemcachedRegion implements En
4343
private final Settings settings;
4444

4545
public MemcachedEntityRegion(MemcachedCache cache, Settings settings, CacheDataDescription metadata, Properties properties, Memcache client) {
46-
super(cache);
46+
super(cache, properties);
4747
this.metadata = metadata;
4848
this.settings = settings;
4949
}

src/main/java/com/mc/hibernate/memcached/region/MemcachedNaturalIdRegion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class MemcachedNaturalIdRegion extends AbstractMemcachedRegion implements
4141
private final Settings settings;
4242

4343
public MemcachedNaturalIdRegion(MemcachedCache cache, Settings settings, CacheDataDescription metadata, Properties properties, Memcache client) {
44-
super(cache);
44+
super(cache, properties);
4545
this.metadata = metadata;
4646
this.settings = settings;
4747
}

src/main/java/com/mc/hibernate/memcached/region/MemcachedQueryResultsRegion.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222

2323
import com.mc.hibernate.memcached.MemcachedCache;
2424

25+
import java.util.Properties;
26+
2527
public class MemcachedQueryResultsRegion extends AbstractMemcachedRegion implements QueryResultsRegion {
2628

2729
private final Logger log = LoggerFactory.getLogger(MemcachedQueryResultsRegion.class);
2830

29-
public MemcachedQueryResultsRegion(MemcachedCache cache) {
30-
super(cache);
31+
public MemcachedQueryResultsRegion(MemcachedCache cache, Properties properties) {
32+
super(cache, properties);
3133
}
3234

3335
public Object get(Object key) throws CacheException {

src/main/java/com/mc/hibernate/memcached/region/MemcachedTimestampsRegion.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222

2323
import com.mc.hibernate.memcached.MemcachedCache;
2424

25+
import java.util.Properties;
26+
2527
public class MemcachedTimestampsRegion extends AbstractMemcachedRegion implements TimestampsRegion {
2628

2729
private final Logger log = LoggerFactory.getLogger(MemcachedTimestampsRegion.class);
2830

29-
public MemcachedTimestampsRegion(MemcachedCache cache) {
30-
super(cache);
31+
public MemcachedTimestampsRegion(MemcachedCache cache, Properties properties) {
32+
super(cache, properties);
3133
}
3234

3335
public Object get(Object key) throws CacheException {

0 commit comments

Comments
 (0)