mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1427 - Map all deleteByIds into a single CacheChangeBeanRemove and use bulk removeAll api to remove from cache
This commit is contained in:
@@ -3,6 +3,7 @@ package io.ebeaninternal.server.cache;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -21,6 +22,8 @@ public class CacheChangeSet {
|
||||
|
||||
private final Set<BeanDescriptor<?>> queryCaches = new HashSet<>();
|
||||
|
||||
private final Map<BeanDescriptor<?>, CacheChangeBeanRemove> beanRemoveMap = new HashMap<>();
|
||||
|
||||
private final Map<ManyKey, ManyChange> manyChangeMap = new HashMap<>();
|
||||
|
||||
private final long modificationTimestamp;
|
||||
@@ -54,6 +57,9 @@ public class CacheChangeSet {
|
||||
for (CacheChange entry : manyChangeMap.values()) {
|
||||
entry.apply();
|
||||
}
|
||||
for (CacheChange entry : beanRemoveMap.values()) {
|
||||
entry.apply();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,8 +108,26 @@ public class CacheChangeSet {
|
||||
* Remove a bean from the cache.
|
||||
*/
|
||||
public <T> void addBeanRemove(BeanDescriptor<T> desc, Object id) {
|
||||
touchedTables.add(desc.getBaseTable());
|
||||
entries.add(new CacheChangeBeanRemove(desc, id));
|
||||
CacheChangeBeanRemove entry = beanRemoveMap.get(desc);
|
||||
if (entry != null) {
|
||||
entry.addId(id);
|
||||
} else {
|
||||
beanRemoveMap.put(desc, new CacheChangeBeanRemove(id, desc));
|
||||
touchedTables.add(desc.getBaseTable());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a bean from the cache.
|
||||
*/
|
||||
public <T> void addBeanRemoveMany(BeanDescriptor<T> desc, Collection<Object> ids) {
|
||||
CacheChangeBeanRemove entry = beanRemoveMap.get(desc);
|
||||
if (entry != null) {
|
||||
entry.addIds(ids);
|
||||
} else {
|
||||
beanRemoveMap.put(desc, new CacheChangeBeanRemove(desc, ids));
|
||||
touchedTables.add(desc.getBaseTable());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user