mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-19 23:02:24 +00:00
#2385 - Redis L2 cache regression - MPUT not working
This commit is contained in:
1 parent
13c94ac78d
commit
d0909ad140
3 files changed
+80
-5
No files matched your search
@@ -8,6 +8,7 @@ import io.ebean.meta.MetricVisitor;
|
|||||||
import io.ebean.metric.CountMetric;
|
import io.ebean.metric.CountMetric;
|
||||||
import io.ebean.metric.MetricFactory;
|
import io.ebean.metric.MetricFactory;
|
||||||
import io.ebean.metric.TimedMetric;
|
import io.ebean.metric.TimedMetric;
|
||||||
|
import io.ebean.metric.TimedMetricStats;
|
||||||
import io.ebean.redis.encode.Encode;
|
import io.ebean.redis.encode.Encode;
|
||||||
import io.ebean.redis.encode.EncodePrefixKey;
|
import io.ebean.redis.encode.EncodePrefixKey;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -188,6 +189,7 @@ final class RedisCache implements ServerCache {
|
|||||||
multi.set(key(entry.getKey()), value(entry.getValue()), expiration);
|
multi.set(key(entry.getKey()), value(entry.getValue()), expiration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
multi.exec();
|
||||||
}
|
}
|
||||||
metricPutAll.addSinceNanos(start);
|
metricPutAll.addSinceNanos(start);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -285,9 +287,13 @@ final class RedisCache implements ServerCache {
|
|||||||
cacheStats.setCacheName(cacheKey);
|
cacheStats.setCacheName(cacheKey);
|
||||||
cacheStats.setHitCount(hitCount.get(reset));
|
cacheStats.setHitCount(hitCount.get(reset));
|
||||||
cacheStats.setMissCount(missCount.get(reset));
|
cacheStats.setMissCount(missCount.get(reset));
|
||||||
cacheStats.setPutCount(metricPut.collect(reset).count());
|
cacheStats.setPutCount(count(metricPut.collect(reset)));
|
||||||
cacheStats.setRemoveCount(metricRemove.collect(reset).count());
|
cacheStats.setRemoveCount(count(metricRemove.collect(reset)));
|
||||||
cacheStats.setClearCount(metricClear.collect(reset).count());
|
cacheStats.setClearCount(count(metricClear.collect(reset)));
|
||||||
return cacheStats;
|
return cacheStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long count(TimedMetricStats stats) {
|
||||||
|
return stats == null ? 0 : stats.count();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package org.domain;
|
||||||
|
|
||||||
|
|
||||||
|
import io.ebean.annotation.Cache;
|
||||||
|
import io.ebean.annotation.CacheBeanTuning;
|
||||||
|
import io.ebean.annotation.Index;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
@Cache(naturalKey = "name")
|
||||||
|
@Entity
|
||||||
|
public class RCust extends EBase {
|
||||||
|
|
||||||
|
@Index(unique = true)
|
||||||
|
String name;
|
||||||
|
|
||||||
|
public RCust(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,20 +1,67 @@
|
|||||||
package org.integration;
|
package org.integration;
|
||||||
|
|
||||||
import io.ebean.DB;
|
import io.ebean.DB;
|
||||||
|
import io.ebean.cache.ServerCache;
|
||||||
|
import io.ebean.cache.ServerCacheStatistics;
|
||||||
import org.domain.Person;
|
import org.domain.Person;
|
||||||
|
import org.domain.RCust;
|
||||||
import org.domain.query.QPerson;
|
import org.domain.query.QPerson;
|
||||||
|
import org.domain.query.QRCust;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class IntegrationTest {
|
class IntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws InterruptedException {
|
void mput() throws InterruptedException {
|
||||||
|
|
||||||
|
ServerCache beanCache = DB.cacheManager().beanCache(RCust.class);
|
||||||
|
beanCache.clear();
|
||||||
|
beanCache.statistics(true);
|
||||||
|
|
||||||
|
List<RCust> people = new ArrayList<>();
|
||||||
|
for (String name : new String[]{"mp0", "mp1", "mp2"}) {
|
||||||
|
people.add(new RCust(name));
|
||||||
|
}
|
||||||
|
DB.saveAll(people);
|
||||||
|
List<Long> ids = people.stream().map(RCust::getId).collect(Collectors.toList());
|
||||||
|
|
||||||
|
List<RCust> f0 = new QRCust()
|
||||||
|
.setIdIn(ids.toArray())
|
||||||
|
.findList();
|
||||||
|
|
||||||
|
assertThat(f0).hasSize(3);
|
||||||
|
ServerCacheStatistics stats0 = beanCache.statistics(true);
|
||||||
|
assertThat(stats0.getHitCount()).isEqualTo(0);
|
||||||
|
|
||||||
|
Thread.sleep(5);
|
||||||
|
|
||||||
|
// we will hit the cache this time
|
||||||
|
List<RCust> f1 = new QRCust()
|
||||||
|
.setIdIn(ids.toArray())
|
||||||
|
.findList();
|
||||||
|
|
||||||
|
assertThat(f1).hasSize(3);
|
||||||
|
ServerCacheStatistics stats1 = beanCache.statistics(true);
|
||||||
|
assertThat(stats1.getHitCount()).isEqualTo(3);
|
||||||
|
|
||||||
|
// we will hit the cache again
|
||||||
|
List<RCust> f2 = new QRCust()
|
||||||
|
.setIdIn(ids.toArray())
|
||||||
|
.findList();
|
||||||
|
assertThat(f2).hasSize(3);
|
||||||
|
ServerCacheStatistics stats2 = beanCache.statistics(true);
|
||||||
|
assertThat(stats2.getHitCount()).isEqualTo(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test() throws InterruptedException {
|
||||||
|
|
||||||
insertSomePeople();
|
insertSomePeople();
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user