mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1427 - QueryCache should be cleared, if one of a dependent bean is updated
Initial work, does not include propagation across cluster.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package org.tests.cache;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.cache.ServerCache;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Address;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestQueryCacheTableDependency extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testFindCountOnDependent() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
ServerCache customerCache = Ebean.getServerCacheManager().getQueryCache(Customer.class);
|
||||
customerCache.clear();
|
||||
|
||||
List<Address> addrs = Ebean.find(Address.class)
|
||||
.where().eq("line2", "St Lukes")
|
||||
.findList();
|
||||
|
||||
int custs = Ebean.find(Customer.class).setUseQueryCache(true).setReadOnly(true)
|
||||
.where().eq("billingAddress.line2", "St Lukes")
|
||||
.findCount();
|
||||
|
||||
assertThat(custs).isEqualTo(3);
|
||||
|
||||
custs = Ebean.find(Customer.class).setUseQueryCache(true).setReadOnly(true)
|
||||
.where().eq("billingAddress.line2", "St Lukes")
|
||||
.findCount();
|
||||
|
||||
assertThat(custs).isEqualTo(3);
|
||||
|
||||
Address a1 = addrs.get(0);
|
||||
a1.setLine2("St Lucky");
|
||||
Ebean.save(a1);
|
||||
|
||||
custs = Ebean.find(Customer.class).setUseQueryCache(true).setReadOnly(true)
|
||||
.where().eq("billingAddress.line2", "St Lukes")
|
||||
.findCount();
|
||||
|
||||
assertThat(custs).isEqualTo(2); // cache says 3
|
||||
|
||||
|
||||
custs = Ebean.find(Customer.class).setUseQueryCache(true).setReadOnly(true)
|
||||
.where().eq("billingAddress.line2", "St Lucky")
|
||||
.findCount();
|
||||
|
||||
assertThat(custs).isEqualTo(1);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.tests.model.basic;
|
||||
|
||||
import io.ebean.annotation.InvalidateQueryCache;
|
||||
import org.tests.model.basic.metaannotation.SizeMedium;
|
||||
|
||||
import javax.persistence.Column;
|
||||
@@ -14,6 +15,11 @@ import java.sql.Timestamp;
|
||||
/**
|
||||
* Address entity bean.
|
||||
*/
|
||||
// Address is not L2 cached directly but it is joined to queries that are cached
|
||||
// What InvalidateQueryCache means is that we propagate a table modification event
|
||||
// when address is changed ... and cached queries that join to address will be
|
||||
// invalidated accordingly.
|
||||
@InvalidateQueryCache
|
||||
@Entity
|
||||
@Table(name = "o_address")
|
||||
public class Address {
|
||||
|
||||
Reference in New Issue
Block a user